-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCodeForces 1504C - Balance the Bits.cpp
More file actions
62 lines (50 loc) · 1.45 KB
/
CodeForces 1504C - Balance the Bits.cpp
File metadata and controls
62 lines (50 loc) · 1.45 KB
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
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define inc(a) a.begin(), a.end()
#define dec(a) a.rbegin(), a.rend()
#define Unique(n) (n).erase(unique(inc(n)), (n).end())
#define what_is(x) cerr << #x << " is " << x << '\n';
#define to(i, a, n) for(int i=a; i<n; i++)
#define fr(i, a, n) for(int i=a; i>=n; i--)
#define read(arr, l, r) for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r) for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])
typedef long long ll;
typedef long double ld;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
const int N = 3E5+5;
string s, a, b;
int t, n, x, y, z, c, ok;
void solve(){
x = y = z = c = ok = 0;
for(int i=0; i<n; ++i) x += (s[i] == '1');
if(x & 1) return cout << "NO\n", void();
for(y=0; y<n; ++y){
if(s[y] == '1') ++c;
if(c == x/2) break;
}
a.clear(), b.clear();
for(int i=0; i<n; ++i){
if(s[i] == '1'){
if(i <= y) a += "(", b += "(", ++z;
else a += ")", b += ")", --z;
}else{
if(ok) a += ")", b += "(", ++z;
else a += "(", b += ")", --z;
ok = !ok;
}
if(z < 0) return cout << "NO\n", void();
}
cout << "YES\n" << a << '\n' << b << '\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while(t--){
cin >> n >> s;
solve();
}
return 0;
}