-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBCSON.cpp
More file actions
28 lines (25 loc) · 697 Bytes
/
BCSON.cpp
File metadata and controls
28 lines (25 loc) · 697 Bytes
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
#include <iostream>
using namespace std;
int main()
{
int n,m;
long long s=0;
cin >> m >> n;
s=m*n;
long a[m+2][n+2];
for(int i=0;i<m+2;i++)
for(int j=0;j<n+2;j++)
{
if(i==0||i==m+1||j==0||j==n+1) a[i][j]=0;
else cin >> a[i][j];
}
for(int i=1;i<m+1;i++)
for(int j=1;j<n+1;j++)
{
if(a[i][j]>a[i-1][j]) s+=(a[i][j]-a[i-1][j]); //vi tri tren
if(a[i][j]>a[i+1][j]) s+=(a[i][j]-a[i+1][j]); //vi tri duoi
if(a[i][j]>a[i][j-1]) s+=(a[i][j]-a[i][j-1]); //vi tri trai
if(a[i][j]>a[i][j+1]) s+=(a[i][j]-a[i][j+1]); //vi tri phai
}
cout << s;
}