-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Balance_the_Bits.cpp
More file actions
48 lines (47 loc) · 985 Bytes
/
A_Balance_the_Bits.cpp
File metadata and controls
48 lines (47 loc) · 985 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long int ll;
const int N = 2e3 + 100;
const int mod = 1e9 + 7;
void code() {
int n;
string s;
cin >> n >> s;
int cnt = 0;
for(int i = 0; i < n; i++) {
cnt += (s[i] == '1');
}
if(cnt % 2 == 1 || s[0] == '0' || s.back() == '0') {
cout << "NO\n";
return;
}
string a, b;
int k = 0;
bool flip = false;
for(int i = 0; i < n; i++) {
if(s[i] == '1') {
a.push_back(2 * k < cnt ? '(' : ')');
b.push_back(a.back());
k++;
}else {
a.push_back(flip ? '(' : ')');
b.push_back(flip ? ')' : '(');
flip = !flip;
}
}
cout << "YES\n" << a << '\n' << b << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;cin>>t;
while(t--)
{
code();
}
return 0;
} //Code Contributed by Harshit Varshney