# BOJ - 1780 - 종이의 개수

Updated:

``````import sys

minus = 0
one = 0
zero = 0

def recursive(maps, N, x1, x2, y1, y2):
global minus, one, zero

color = maps[x1][y1]
for i in range(x1, x2):
for j in range(y1, y2):
if maps[i][j] != color:
color = -5
break
if color == -5:
break

if color == 0:
zero += 1
elif color == 1:
one += 1
elif color == -1:
minus += 1

if color == -5:
div = N // 3
recursive(maps, div, x1, x1 + div, y1, y1 + div)
recursive(maps, div, x1, x1 + div, y1 + div, y1 + div * 2)
recursive(maps, div, x1, x1 + div, y1 + div * 2, y1 + N)

recursive(maps, div, x1 + div, x1 + div * 2, y1, y1 + div)
recursive(maps, div, x1 + div, x1 + div * 2, y1 + div, y1 + div * 2)
recursive(maps, div, x1 + div, x1 + div * 2, y1 + div * 2, y1 + N)

recursive(maps, div, x1 + div * 2, x1 + N, y1, y1 + div)
recursive(maps, div, x1 + div * 2, x1 + N, y1 + div, y1 + div * 2)
recursive(maps, div, x1 + div * 2, x1 + N, y1 + div * 2, y1 + N)

def solution():
N = int(input())
maps = []
for _ in range(N):

recursive(maps, N, 0, N, 0, N)

print(minus)
print(zero)
print(one)
solution()
``````

https://www.acmicpc.net/problem/1780

Categories:

Updated: