-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2630.py
37 lines (29 loc) · 882 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
# 색종이 만들기
import sys
N = int(sys.stdin.readline().rstrip(" "))
papers = []
for _ in range(N):
row = list(map(int, sys.stdin.readline().split(" ")))
papers.append(row)
def check(root):
stack = [root]
white = 0
blue = 0
while stack:
color = 0
x1, x2, y1, y2 = stack.pop()
for y in range(y1, y2):
color += sum(papers[y][x1:x2])
if color == (x2 - x1) * (y2 - y1):
blue += 1
elif color == 0:
white += 1
else:
stack.append([x1, (x1 + x2) // 2, y1, (y1 + y2) // 2])
stack.append([x1, (x1 + x2) // 2, (y1 + y2) // 2, y2])
stack.append([(x1 + x2) // 2, x2, y1, (y1 + y2) // 2])
stack.append([(x1 + x2) // 2, x2, (y1 + y2) // 2, y2])
return white, blue
white, blue = check([0, N, 0, N])
print(white)
print(blue)