-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
83 lines (78 loc) · 2.07 KB
/
Copy pathmain.cpp
File metadata and controls
83 lines (78 loc) · 2.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
int N, L, map[105][105];
int main(void) {
scanf("%d %d", &N, &L); // n^2
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
scanf("%d", &map[i][j]);
int ans = 2 * N;
// row
for(int i=0; i<N; i++) {
int bh = map[i][0], ch, cnt = 1;
for(int j=1; j<N; j++) {
ch = map[i][j];
if(ch == bh) {
cnt++;
} else if(ch == bh + 1) {
if(cnt >= L) {
bh = ch;
cnt = 1;
} else {
ans--;
break;
}
} else if(ch == bh - 1){
for(cnt = 1; cnt < L; cnt++) {
if(j+cnt >= N || map[i][j+cnt] != ch)
break;
}
if(cnt >= L) {
bh = ch;
j += L - 1;
cnt = 0;
} else {
ans--;
break;
}
} else {
ans--;
break;
}
}
}
for(int i=0; i<N; i++) {
int bh = map[0][i], ch, cnt = 1;
for(int j=1; j<N; j++) {
ch = map[j][i];
if(ch == bh) {
cnt++;
continue;
} else if(ch == bh+1) {
if(cnt >= L) {
bh = ch;
cnt = 1;
} else {
ans--;
break;
}
} else if(ch == bh - 1) {
for(cnt = 1; cnt < L; cnt++) {
if(j+cnt >= N || map[j+cnt][i] != ch) break;
}
if(cnt >= L){
bh = ch;
j += L-1;
cnt = 0;
} else {
ans--;
break;
}
} else {
ans--;
break;
}
}
}
printf("%d\n", ans);
return 0;
}