-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathb.cc
49 lines (46 loc) · 899 Bytes
/
b.cc
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
// http://codeforces.com/contest/984/problem/B
#include <bits/stdc++.h>
using namespace std;
int a[101][101];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
char c = s[j];
switch (c) {
case '*':
a[i][j] = -1;
break;
case '.':
a[i][j] = 0;
break;
default:
a[i][j] = c - '0';
}
}
}
bool ok = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == -1) continue;
int y[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int c = 0;
for (int k = 0; k < 8; k++) {
int yy = i + y[k];
int xx = j + x[k];
if (yy < 0 || yy >= n || xx < 0 || xx >= m) continue;
c += a[yy][xx] == -1;
}
if (c != a[i][j]) {
ok = false;
break;
}
}
if (!ok) break;
}
cout << (ok ? "YES\n": "NO\n");
}