-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCF_483_Div2_B.cpp
More file actions
60 lines (59 loc) · 1.35 KB
/
CF_483_Div2_B.cpp
File metadata and controls
60 lines (59 loc) · 1.35 KB
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int mat[n][m];
for(int i=0;i<n;i++)
{
string st;
cin>>st;
for(long int j=0;j<st.length();j++)
{
if(st[j]=='.')
mat[i][j]=0;
else if(st[j]=='*')
mat[i][j]=10;
else
mat[i][j]=st[j]-'0';
}
}
/* for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<mat[i][j]<<" ";
cout<<endl;
} */
bool flag=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(mat[i][j]>=0&&mat[i][j]<=8)
{
int cur=0;
int lr=max(0,i-1);
int rr=min(n-1,i+1);
int lc=max(0,j-1);
int rc=min(m-1,j+1);
for(int k=lr;k<=rr;k++)
{
for(int l=lc;l<=rc;l++)
if(mat[k][l]==10)
cur++;
}
// cout<<i<<" "<<j<<" "<<cur<<endl;
if(cur!=mat[i][j])
{
flag=0;
break;
}
}
}
}
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}