-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path892.cpp
75 lines (62 loc) · 1.44 KB
/
892.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class Solution {
public:
int surfaceArea(vector<vector<int>>& A) {
int m=A.size();
int n=A[0].size();
int sum=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
sum+=A[i][j];
}
}
sum=sum*6;
// cout<<sum<<" ";
int sum1=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n-1;j++)
{
if(A[i][j]<A[i][j+1])
{
sum1+=(A[i][j]);
}
else
{
sum1+=(A[i][j+1]);
}
}
}
int sum2=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n-1;j++)
{
if(A[j][i]<A[j+1][i])
{
sum2+=(A[j][i]);
}
else
{
sum2+=(A[j+1][i]);
}
}
}
// cout<<sum2<<" ";
int sum3=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(A[i][j]>1)
sum3=sum3+((A[i][j]-1));
}
}
// cout<<sum3<<" ";
int x=sum1+sum2+sum3;
int y=2*x;
int l=sum-y;
return l;
}
};