-
Notifications
You must be signed in to change notification settings - Fork 0
/
14890.py
59 lines (35 loc) · 890 Bytes
/
14890.py
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
import sys
N,L = map(int,sys.stdin.readline().split())
board = []
for i in range(N):
board.append(list(map(int,sys.stdin.readline().split())))
answer = 0
for i in range(N):
count = 1
for j in range(N-1):
if board[i][j] == board[i][j+1]:
count += 1
elif board[i][j] + 1 == board[i][j+1] and count >= L:
count = 1
elif board[i][j] - 1 == board[i][j+1] and count >= 0:
count = (1 - L)
else:
count = -1
break
if count >= 0:
answer += 1
for j in range(N):
count = 1
for i in range(N-1):
if board[i][j] == board[i+1][j]:
count += 1
elif board[i][j] + 1 == board[i+1][j] and count >= L:
count = 1
elif board[i][j] - 1 == board[i+1][j] and count >= 0:
count = (1 - L)
else:
count = -1
break
if count >= 0:
answer += 1
print(answer)