-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1992.cpp
53 lines (41 loc) · 964 Bytes
/
P1992.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <cstdio>
using namespace std;
int graph[65][65] = {};
void solve(int size, int x, int y) {
int check = 0;
for (int nx = x; nx < (x + size); nx++) {
for (int ny = y; ny < (y + size); ny++) {
if (graph[ny][nx] != graph[y][x]) {
check = 1;
}
}
}
if (!check) {
cout << graph[y][x];
return;
}
int next_size = size / 2;
int next_x = x + next_size;
int next_y = y + next_size;
cout << "(";
solve(next_size, x, y);
solve(next_size, x, next_y);
solve(next_size, next_x, y);
solve(next_size, next_x, next_y);
cout << ")";
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%1d", &graph[j][i]);
}
}
if(N == 1) cout << graph[0][0];
else solve(N, 0, 0);
return 0;
}