-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2630.py
48 lines (37 loc) · 854 Bytes
/
2630.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
from collections import deque
N = int(input())
MAP = []
for i in range(N):
lane = list(map(int, input().split()))
MAP.append(lane)
MIX = -1
BLUE = 1
WHITE = 0
def check_color(sx, sy, l):
first_color = MAP[sy][sx]
for x in range(sx, sx + l):
for y in range(sy, sy + l):
if MAP[y][x] != first_color:
return MIX
return first_color
Q = deque()
Q.append((0, 0, N))
white_cnt = 0
blue_cnt = 0
while Q:
x, y, l = Q.popleft()
color_on_sq = check_color(x, y, l)
if color_on_sq == WHITE:
white_cnt += 1
elif color_on_sq == BLUE:
blue_cnt += 1
else:
nl = l // 2
nx = x + nl
ny = y + nl
Q.append((x, y, nl))
Q.append((nx, y, nl))
Q.append((x, ny, nl))
Q.append((nx, ny, nl))
print(white_cnt)
print(blue_cnt)