-
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))
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 1780번 종이의 개수 (파이썬) (0) 2022.01.02 [백준] 1992번 쿼드트리 (파이썬) (0) 2022.01.02 [백준] 1010번 다리 놓기 (파이썬) (0) 2022.01.02 [백준] 11050번 이항 계수 1 (파이썬) (0) 2022.01.02 [백준] 12865번 평범한 배낭 (파이썬) (0) 2022.01.02