#P1187. 3D模型
3D模型
Description
A city is built on a regular grid, where each cell is a square. Each cell may contain a building, which is constructed from some number of cubes (that is, all building bases lie on the same plane). Several typical city models are shown below:

Now the height of the building on each grid cell is given, i.e., how many cubes are stacked on that cell. Determine the surface area of this city model.
Input Format
The first line contains 2 positive integers , the length and width of the city model.
Then follow lines, each containing digit characters, describing the height of each cell (all building heights are greater than or equal to and less than or equal to ).
Output Format
A non-negative integer: the surface area of the city model.
3 3
111
212
111
38
3 4
1000
0010
0000
12
Hint
- 20% of the testdata satisfy: ;
- 40% of the testdata satisfy: ;
- 100% of the testdata satisfy: .
Translated by ChatGPT 5
京公网安备 11011102002149号