#6. 3D模型

3D模型

说明

一座城市建立在规则的 <math xmlns="http://www.w3.org/1998/Math/MathML">n×m 网格上,并且网格均由 <math xmlns="http://www.w3.org/1998/Math/MathML">1×1 正方形构成。在每个网格上都可以有一个建筑,建筑由若干个 <math xmlns="http://www.w3.org/1998/Math/MathML">1×1×1 的立方体搭建而成(也就是所有建筑的底部都在同一平面上的)。几个典型的城市模型如下图所示:
现在给出每个网格上筑的高度,即每个网格上建筑由多少个立方体搭建而成,要求这个建筑模型的表面积是多少。

输入格式

第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 行包含 <math xmlns="http://www.w3.org/1998/Math/MathML">2 个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML">n,m,为城市模型的长与宽。

接下来 <math xmlns="http://www.w3.org/1998/Math/MathML">n 行,每行 <math xmlns="http://www.w3.org/1998/Math/MathML">m 个数字字符,描述了网格每个格子高度(可见所有建筑高度都大于等于 <math xmlns="http://www.w3.org/1998/Math/MathML">0 且小于等于 <math xmlns="http://www.w3.org/1998/Math/MathML">9)。

输出格式

一个非负整数,为城市模型的表面积。
3 3
111
212
111
38

提示


  • <math xmlns="http://www.w3.org/1998/Math/MathML">20% 的数据满足:<math xmlns="http://www.w3.org/1998/Math/MathML">n,m10

  • <math xmlns="http://www.w3.org/1998/Math/MathML">40% 的数据满足:<math xmlns="http://www.w3.org/1998/Math/MathML">n,m100

  • <math xmlns="http://www.w3.org/1998/Math/MathML">100% 的数据满足:<math xmlns="http://www.w3.org/1998/Math/MathML">1n,m1000

来源

模拟