✔ 풀이를 위한 아이디어
✔ 코드
import sys
papers = []
count_w = 0
count_b = 0
def check(start_x, start_y, n):
global count_w
global count_b
tmp = papers[start_y][start_x] # 탐색 영역의 첫번째 값을 저장
for j in range(start_y, start_y+n):
for i in range(start_x, start_x+n):
if papers[j][i] != tmp:
check(start_x, start_y, n//2)
check(start_x + n//2, start_y, n//2)
check(start_x, start_y + n//2, n//2)
check(start_x + n//2, start_y + n//2, n//2)
return
if tmp:
count_b += 1
else:
count_w += 1
N = int(input())
for _ in range(N):
papers.append(list(map(int, sys.stdin.readline().split())))
check(0, 0, N)
print(count_w)
print(count_b)
✔ 관련 개념