#P1187. Surface Area of Cubic Buildings
Surface Area of Cubic Buildings
Surface Area of Cubic Buildings
Given a city built on a regular grid where each cell may contain a building constructed by stacking cubes (all buildings share the same base). The height at each cell represents the number of cubes used. Calculate the total surface area of the resulting 3D model.
The surface area includes the top, bottom, and all exposed side surfaces of the buildings. When two adjacent buildings touch, the area between them is not counted.
inputFormat
The first line contains two integers and representing the dimensions of the grid. Each of the following lines contains integers, where each integer represents the height of the building at that cell.
outputFormat
Output a single integer that represents the total surface area of the building model.
sample
1 1
2
10
</p>