Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 889 Bytes

1992.md

File metadata and controls

37 lines (31 loc) · 889 Bytes

백준 1992번 쿼드트리

1992


소스코드

  • 메모리 : 30864 KB
  • 시간 : 76 ms
def solution(x, y, n):
    check = matrix[x][y]
    for i in range(x,x+n):
        for j in range(y,y+n):
            if check != matrix[i][j]:
                print('(', end='')
                solution(x,y,n//2)
                solution(x,y+n//2,n//2)
                solution(x+n//2,y,n//2)
                solution(x+n//2,y+n//2,n//2)
                print(')', end='')
                return
 
    if check == 0:
        print('0',end='')
        return
    else:   
        print('1',end='')
        return

n = int(input())
matrix = [list(map(int,input())) for i in range(n)]
solution(0,0,n)