분할정복쓰
import sys
input = sys.stdin.readline
def check(x,y,size):
color = matrix[x][y]
for i in range(x,x+size):
for j in range(y,y+size):
if not color==matrix[i][j]:
return False
if color==1:
answer[1] += 1
else:
answer[0] += 1
return True
def divide_paper(start_x,start_y,length):
if not check(start_x,start_y,length//2):
divide_paper(start_x,start_y,length//2)
if not check(start_x+length//2,start_y,length//2):
divide_paper(start_x+length//2,start_y,length//2)
if not check(start_x,start_y+length//2,length//2):
divide_paper(start_x,start_y+length//2,length//2)
if not check(start_x+length//2,start_y+length//2,length//2):
divide_paper(start_x+length//2,start_y+length//2,length//2)
N = int(input())
matrix = [list(map(int, input().split())) for _ in range(N)]
answer = [0,0]
if not check(0,0,N):
divide_paper(0,0,N)
for color in answer:
print(color)
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 7576 토마토 (0) | 2021.08.27 |
---|---|
[백준][Python] 1244 스위치 켜고 끄기 (0) | 2021.08.27 |
[백준][Python] 21939 문제 추천 시스템 (0) | 2021.08.26 |
[백준][Python] 22867 종점 (0) | 2021.08.26 |
[백준][Python] 22941 RPG마스터 오명진 (0) | 2021.08.26 |