728x90
반응형
https://www.acmicpc.net/problem/1992
import sys
input = sys.stdin.readline
N = int(input())
video = [input().rstrip() for _ in range(N)]
result = ""
def checkVideo(video, num):
global result
if num < 2:
value = video[0][0]
result += value
return
stdValue = None
isBreak = False
for i in range(num):
for j in range(num):
if stdValue == None:
stdValue = video[i][j]
elif stdValue != video[i][j]:
isBreak = True
break
if isBreak:
break
if isBreak:
newNum = num // 2
if num == 2:
value = "(" + video[0][0] + video[0][1] + video[1][0] + video[1][1] + ")"
result += value
return
result += "("
leftTopVideo = []
for x in range(0, newNum):
elems = []
for y in range(0, newNum):
elems.append(video[x][y])
leftTopVideo.append(elems)
checkVideo(leftTopVideo, newNum)
rightTopVideo = []
for x in range(0, newNum):
elems = []
for y in range(newNum, num):
elems.append(video[x][y])
rightTopVideo.append(elems)
checkVideo(rightTopVideo, newNum)
leftBottomVideo = []
for x in range(newNum, num):
elems = []
for y in range(0, newNum):
elems.append(video[x][y])
leftBottomVideo.append(elems)
checkVideo(leftBottomVideo, newNum)
rightBottomVideo = []
for x in range(newNum, num):
elems = []
for y in range(newNum, num):
elems.append(video[x][y])
rightBottomVideo.append(elems)
checkVideo(rightBottomVideo, newNum)
result += ")"
else:
value = stdValue
result += value
return
checkVideo(video, N)
print(result)
728x90
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
BOJ 1463 1로 만들기 Python3 (0) | 2023.06.28 |
---|---|
BOJ 12100 2048 (Easy) Python3 (0) | 2023.06.27 |
17142 java 연습 (0) | 2021.08.12 |
셀프 넘버(4673번 문제) Python3 답안 (0) | 2020.02.09 |
한수(1065번 문제) Python3 답안 (0) | 2020.02.09 |