-
Notifications
You must be signed in to change notification settings - Fork 559
/
1992.cpp
49 lines (48 loc) · 1.01 KB
/
1992.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
// Authored by : cpprhtn
// Co-authored by : -
// http://boj.kr/04267bd2251a41109700585bc73a6de2
#include <bits/stdc++.h>
using namespace std;
int N;
const int MAX = 64;
int arr[MAX][MAX];
void solve(int n, int y, int x)
{
if (n == 1) {
cout << arr[y][x];
return;
}
bool zero = true, one = true;
for (int i = y; i < y + n; i++)
for (int j = x; j < x + n; j++)
if (arr[i][j])
zero = false;
else
one = false;
if (zero)
cout << 0;
else if (one)
cout << 1;
else {
cout << "(";
solve(n / 2, y, x); //왼쪽 위
solve(n / 2, y, x + n / 2); //오른쪽 위
solve(n / 2, y + n / 2, x); //왼쪽 아래
solve(n / 2, y + n / 2, x + n / 2); //오른쪽 아래
cout << ")";
}
return;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
string str;
cin >> str;
for (int j = 0; j < N; j++)
arr[i][j] = str[j] - '0';
}
solve(N, 0, 0);
}