매번 나오는 분할정복 문제.
import sys
input = sys.stdin.readline
def check(n,s_x,s_y):
pivot = matrix[s_x][s_y]
for i in range(s_x,s_x+n):
for j in range(s_y,s_y+n):
if matrix[i][j] != pivot:
return False
return True
def divide_paper(n,s_x,s_y):
global papers
pivot = n//3
if n==1:
papers[matrix[s_x][s_y]] += 1
return
if check(n,s_x,s_y):
papers[matrix[s_x][s_y]] += 1
return
for i in range(3):
for j in range(3):
divide_paper(pivot,s_x+(pivot*i),s_y+(pivot*j))
N = int(input())
matrix = [list(map(int,input().split())) for _ in range(N)]
papers = {-1: 0, 0: 0, 1: 0}
divide_paper(N,0,0)
for paper in papers:
print(papers[paper])
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 2667 단지번호붙이기 (0) | 2021.09.03 |
---|---|
[백준][Python] 1992 쿼드트리 (0) | 2021.09.03 |
[백준][Python] 2876 그래픽스 퀴즈 (0) | 2021.09.03 |
[백준][Python] 4134 다음 소수 (0) | 2021.09.03 |
[백준][Python] 16934 게임닉네임 : Trie (0) | 2021.09.03 |