💡문제접근
- 이전에 풀었던 [[백준] 1992번 쿼드트리] 문제를 먼저 풀고 나서 풀었더니 수월하게 풀 수 있었던 문제
💡코드(메모리 : 31256KB, 시간 : 60ms)
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
color_paper = []
for _ in range(N):
color_paper.append(list(map(int, input().strip().split())))
result = [0, 0]
def recursive(x, y, N):
global result
position = color_paper[x][y]
for i in range(x, x + N):
for j in range(y, y + N):
if color_paper[i][j] != position:
recursive(x, y, N // 2)
recursive(x, y + N // 2, N // 2)
recursive(x + N // 2, y, N // 2)
recursive(x + N // 2, y + N // 2, N // 2)
return
if position == 1:
result[1] += 1
else:
result[0] += 1
recursive(0, 0, N)
print(result[0])
print(result[1])
💡소요시간 : 17m