[Link] https://www.acmicpc.net/problem/14890
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
84
85
86
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
typedef long long ll;
const int INF = 987654321;
const int MAX = 100;
int n, l, ans;
int mm[MAX][MAX];
int mm_rev[MAX][MAX];
void init_rev_mm() {
for0(i, n) {
for0(j, n) {
mm_rev[i][j] = mm[j][i];
}
}
}
void count(int mm[MAX][MAX]) {
for0(i, n) {
int tmp = mm[i][0];
int cnt = 1;
bool decreased = false;
bool can = true;
for1(j, n) {
if(mm[i][j] == tmp) {
cnt++;
continue;
}
if(abs(mm[i][j] - tmp) > 1) {
can = false;
break;
}
else if(mm[i][j] > tmp) {
if(decreased) {
if(cnt < l << 1) {
can = false;
break;
}
} else {
if(cnt < l) {
can = false;
break;
}
}
cnt = 1;
decreased = false;
tmp = mm[i][j];
} else {
if(decreased) {
if(cnt < l) {
can = false;
break;
}
}
cnt = 1;
decreased = true;
tmp = mm[i][j];
}
}
if(decreased) if(cnt < l) can = false;
if(can) ans++;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> l;
for0(i, n) {
for0(j, n) cin >> mm[i][j];
}
init_rev_mm();
count(mm);
count(mm_rev);
cout << ans;
return 0;
}