-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaekJoon1992.py
31 lines (27 loc) · 911 Bytes
/
BaekJoon1992.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# BaekJoon 1992.py
def solution(arr, pos, x, y, result):
if pos == 1:
return result + str(arr[y][x])
# 모두 같은지 체크
is_same = True
value = arr[y][x]
for i in range(pos):
for j in range(pos):
if arr[y+i][x+j] != value:
is_same = False
# 같으면
if is_same:
return result + str(arr[y][x])
# 다르면
elif not is_same:
result = result + "("
result = solution(arr, int(pos / 2), x, y, result)
result = solution(arr, int(pos / 2), int(x + (pos / 2)), y, result)
result = solution(arr, int(pos / 2), x, int(y + (pos / 2)), result)
result = solution(arr, int(pos / 2), int(x + (pos / 2)), int(y + (pos / 2)), result)
result = result + ")"
return result
N = int(input())
image = [list(map(int, input())) for _ in range(N)]
r = solution(image, N, 0, 0, "")
print(r)