알고리즘/백준

[백준] 2630번 색종이 만들기 (파이썬)

알감자 2022. 1. 2. 01:27
 

2630번: 색종이 만들기

첫째 줄에는 전체 종이의 한 변의 길이 N이 주어져 있다. N은 2, 4, 8, 16, 32, 64, 128 중 하나이다. 색종이의 각 가로줄의 정사각형칸들의 색이 윗줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진다.

www.acmicpc.net

 

 

코드

n = int(input())
li = []

for _ in range(n):
    li.append(list(map(int, input().split(" "))))

answer = []

def find(x, y, N):
    color = li[x][y]
    for i in range(x, x+N):
        for j in range(y, y+N):
            if li[i][j] != color:
                find(x,y, N//2)
                find(x, y+N//2, N//2)
                find(x+N//2, y, N//2)
                find(x+N//2, y+N//2, N//2)
                return
                
    if color == 0:
        answer.append(0)
    else:
        answer.append(1)

find(0,0,n)
print(answer.count(0))
print(answer.count(1))