ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 2630 |
문제명 | 색종이 만들기 |
레벨 | 실버 3 |
분류 |
기초 |
시간복잡도 | O(n^2) |
인풋사이즈 | n<=128 |
사용한 언어 | Python |
제출기록 | 29200KB / 92ms |
최고기록 | 64ms |
해결날짜 | 2021/07/27 |
"""Solution code for "BOJ 2630. 색종이 만들기".
- Problem link: https://www.acmicpc.net/problem/2630
- Solution link: http://www.teferi.net/ps/problems/boj/2630
"""
WHITE = '0'
BLUE = '1'
def main():
N = int(input())
colors = [input().split() for _ in range(N)]
white_counts = []
blue_counts = []
for row in colors:
white_counts.append([int(col == WHITE) for col in row])
blue_counts.append([int(col == BLUE) for col in row])
size = 1
while size < N:
delta = [(0, 0), (0, size), (size, 0), (size, size)]
size *= 2
for r in range(0, N, size):
for c in range(0, N, size):
white = sum(white_counts[r + dr][c + dc] for dr, dc in delta)
blue = sum(blue_counts[r + dr][c + dc] for dr, dc in delta)
if white == 4 and blue == 0:
white = 1
elif white == 0 and blue == 4:
blue = 1
white_counts[r][c], blue_counts[r][c] = white, blue
print(white_counts[0][0])
print(blue_counts[0][0])
if __name__ == '__main__':
main()