P28168 [洛谷] 3D Model
普及
题目描述

Problem Description

A city is built on a regular grid of size $n \times m$, where each grid cell is a $1 \times 1$ square. Each grid cell can have a building, which is constructed using several $1 \times 1 \times 1$ cubes (meaning all buildings have their bases on the same plane). Several typical city models are shown in the following image:

Given the height of each building on the grid, i.e., how many cubes are used to construct each building, the task is to determine the surface area of the entire building model.

Input Format

The first line contains two positive integers $n, m$, representing the length and width of the city model.

The next $n$ lines each contain $m$ numeric characters, describing the height of each grid cell (all building heights are between $0$ and $9$ inclusive).

Output Format

A non-negative integer representing the surface area of the city model.

Sample Input and Output

Sample Input #1

3 3
111
212
111

Sample Output #1

38

Sample Input #2

3 4
1000
0010
0000

Sample Output #2

12

Notes/Hints

  • $20\%$ of the test cases satisfy: $n, m \leq 10$;
  • $40\%$ of the test cases satisfy: $n, m \leq 100$;
  • $100\%$ of the test cases satisfy: $1 \leq n, m \leq 1000$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 111 212 111
样例输出
38