-
Notifications
You must be signed in to change notification settings - Fork 0
/
14890.cpp
106 lines (98 loc) · 2.59 KB
/
14890.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <cstring>
#include <cmath>
#define N 105
using namespace std;
int n, l, arr[N][N], ans, built[N];
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int i, j, k;
cin >> n >> l;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
cin >> arr[i][j];
}
for (i = 1; i <= n; i++)
{
memset(built, 0, sizeof(built));
for (j = 2; j <= n; j++)
{
if (abs(arr[i][j - 1] - arr[i][j] > 1))
break;
if (arr[i][j - 1] > arr[i][j])
{
if (j + l - 1 > n)
break;
for (k = j; k < j + l; k++)
{
if (arr[i][j] != arr[i][k] || built[k])
break;
}
if (k < j + l)
break;
for (k = j; k < j + l; k++)
built[k] = 1;
}
else if (arr[i][j - 1] < arr[i][j])
{
if (j <= l)
break;
for (k = j - l; k < j; k++)
{
if (arr[i][j - 1] != arr[i][k] || built[k])
break;
}
if (k < j)
break;
for (k = j - l; k < j; k++)
built[k] = 1;
}
}
if (j > n)
ans++;
}
for (i = 1; i <= n; i++)
{
memset(built, 0, sizeof(built));
for (j = 2; j <= n; j++)
{
if (abs(arr[j][i] - arr[j - 1][i] > 1))
break;
if (arr[j][i] < arr[j - 1][i])
{
if (j + l - 1 > n)
break;
for (k = j; k < j + l; k++)
{
if (arr[j][i] != arr[k][i] || built[k])
break;
}
if (k < j + l)
break;
for (k = j; k < j + l; k++)
built[k] = 1;
}
else if (arr[j][i] > arr[j - 1][i])
{
if (j <= l)
break;
for (k = j - l; k < j; k++)
{
if (arr[j - 1][i] != arr[k][i] || built[k])
break;
}
if (k < j)
break;
for (k = j - l; k < j; k++)
built[k] = 1;
}
}
if (j > n)
ans++;
}
cout << ans;
return 0;
}