eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Surface Area

Surface Area

The solid in the picture below is made up of \textbf{1}×\textbf{1}×\textbf{1} cubes in a \textbf{3D} grid. In this problem, we'll limit ourselves to solids that are made up of columns rooted on the ground (a column consists of one or several \textbf{1}×\textbf{1}×\textbf{1} cubes stacked on top of each other). Such solids can be described as a matrix of digits, where each digit corresponds to the height of a column in the \textbf{2D} grid that makes up the ground. A zero means there is no column at all in that position. \includegraphics{https://static.e-olymp.com/content/06/06a3c68beb7ecf074d87c9b42e478a558aefa1be.jpg} The corresponding matrix for the above solid will be \textbf{4231} \textbf{2101} \textbf{0001} The volume of such a solid is simple enough to calculate, but what we're interested here in the total surface area including the floor (that is, the number of \textbf{1}×\textbf{1} "squares" non hidden on the outer surface). You are given the information of the solid as a matrix. Your task is to compute the surface area of the given solid. You can assume that the solid is always connected, i.e the columns will be attached to each other in the four cardinal directions. \InputFile First line of the input contains \textbf{T}, the number of test cases. Each test case starts with a line containing \textbf{R} and \textbf{C }denoting the number of rows and columns of the solid. Each of the next \textbf{R} lines contains \textbf{C} digits. Each digits are between \textbf{0} to \textbf{9} inclusive. \textbf{R} and \textbf{C} will be between \textbf{1} and \textbf{50} inclusive. \OutputFile For each test case, output the total surface area of the given solid, including the floor area.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
4
1 2
11
3 4
4231
2101
0001
3 3
111
101
111
1 1
5
Вихідні дані #1
10
54
32
22
Джерело ACM-ICPC Malaysia al-Khawārizmī Programming Contest 2011