#include <bits/stdc++.h>
using namespace std;
#define INT long long int
INT n;
vector<string> arr;
INT chk1, chk0;
void f(INT x, INT y, INT l)
{
if(l==1)
{
if(arr[y][x] == '1')
{
cout << "1";
}
else{
cout << "0";
}
return;
}
for(int i=y; i<y+l; i++)
{
for(int j=x; j<x+l; j++)
{
if(arr[i][j] == '0') chk0=1;
else chk1=1;
}
}
if(chk0 && chk1)
{
cout << "(";
chk0 = chk1 = 0;
f(x, y, l/2);
chk0 = chk1 = 0;
f(x+l/2, y, l/2);
chk0 = chk1 = 0;
f(x, y+l/2, l/2);
chk0 = chk1 = 0;
f(x+l/2, y+l/2, l/2);
cout << ")";
}
else{
if(chk0) cout << "0";
else cout << "1";
}
}
int main()
{
cin >> n;
for(int i=0; i<n; i++)
{
string str;
cin >> str;
arr.push_back(str);
}
f(0,0,n);
}
-분할 정복
'코딩 일지 > baekjoon' 카테고리의 다른 글
2630 (0) | 2023.12.28 |
---|---|
2447 (0) | 2023.12.28 |
1260 dfs와 bfs (0) | 2023.08.30 |
1655 가운데를 말해요 (0) | 2023.08.22 |
12865 - 평범한 배낭 (0) | 2023.08.17 |