-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (57 loc) · 1.79 KB
/
Copy pathmain.cpp
File metadata and controls
57 lines (57 loc) · 1.79 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
#include<iostream>
#include<algorithm>
using namespace std;
int n, l, a[101][101], b[101][101], ans;
void check(int row, int a[101][101]) {
bool c[101] = { false, };
int temp = a[row][0];
for (int i = 0; i < n; i++) {
if (a[row][i] != temp) {
if (abs(a[row][i] - temp) > 1) return; //차이가 1보다 클경우
if (a[row][i] < temp) { //다음것이 나보다 작을 경우(오른쪽 경사로)
int num = -1;
for (int j = i; j <= i + l - 1; j++) {
if (j >= n || c[j]) return;
c[j] = true;
if (num == -1) {
num = a[row][j];
continue;
}
if (num != -1 && a[row][j] != num) return;
}
i = i + l - 1;
if (i >= n) break;
}
else { //다음것이 나보다 큰 경우(왼쪽 경사로)
int num = -1;
for (int j = i - 1; j >= i - l; j--) {
if (j < 0 || c[j]) return;
c[j] = true;
if (num == -1) {
num = a[row][j];
continue;
}
if (num != -1 && a[row][j] != num) return;
}
}
temp = a[row][i];
}
}
++ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
cin >> a[i][j];
b[j][i] = a[i][j];
}
for (int i = 0; i < n; i++) {
check(i, a);
check(i, b);
}
cout << ans << endl;
return 0;
}