-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1992.py
More file actions
31 lines (28 loc) · 671 Bytes
/
1992.py
File metadata and controls
31 lines (28 loc) · 671 Bytes
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
import sys
def is_oneqt(i,j, n):
oz = graph[i][j]
for k in range(i, i+n):
for l in range(j, j+n):
if graph[k][l] != oz:
return False
return True
def dfs(i, j, n):
if n==1:
answer.append(graph[i][j])
return
if is_oneqt(i, j, n):
answer.append(graph[i][j])
return
else:
half = n//2
answer.append('(')
dfs(i, j, half)
dfs(i, j + half, half)
dfs(i+half, j, half)
dfs(i + half, j + half, half)
answer.append(')')
n = int(input())
graph = [sys.stdin.readline() for _ in range(n)]
answer = []
dfs(0,0, n)
print(''.join(answer))