BOJ - 2630 - 색종이 만들기

Updated:

import sys

blue, white = 0, 0
def recursive(Field, N, x1, y1, x2, y2):
    global blue, white
    color = Field[x1][y1]
    for i in range(x1, x2):
        for j in range(y1, y2):
            if Field[i][j] != color:
                color = -1
                break
        if color == -1:
            break

    if color == 0:
        white += 1
    elif color == 1:
        blue += 1

    if color == -1:
        div = N // 2
        recursive(Field, div, x1, y1, x1 + div, y1 + div)
        recursive(Field, div, x1 + div, y1, x1 + N, y1 + div)
        recursive(Field, div, x1, y1 + div, x1 + div, y1 + N)
        recursive(Field, div, x1 + div, y1 + div, x1 + N, y1 + N)

def solution():
    N = int(input())
    Field = []
    for _ in range(N):
        Field.append(list(map(int, sys.stdin.readline().split())))

    recursive(Field, N, 0, 0, N, N)

    print(white)
    print(blue)
solution()

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

Categories:

Updated:

Leave a comment