#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int n,d[maxn],nxt[maxn],f[maxn],val[maxn];
char c[maxn];
void solve(){
cin >> n;
for(int i=1;i<=2*n;i++){
cin >> c[i];
nxt[i]=val[i]=f[i]=0;
}
for(int i=1;i<=n;i++){
int a,b;cin >> a >> b;
if(c[a]==c[b]){
if(c[a]=='(') d[i]=0,val[a]++;
else d[i]=1,val[b]--;
}
else{
nxt[a]=b,f[a]=i;
if(c[a]=='(') d[i]=1,val[b]--;
else d[i]=0,val[a]--;
}
}
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
int cnt=0;
for(int i=1;i<=2*n;i++){
if(f[i]) pq.push({nxt[i],f[i]});
cnt+=val[i];
if(cnt<0){
if(pq.empty()) break;
auto [x,id]=pq.top();pq.pop();
d[id]^=1;
if(x<=i) cnt+=2;
else cnt+=1,val[x]--;
}
}
if(cnt) cout << -1 << '\n';
else{
for(int i=1;i<=n;i++) cout << d[i] << ' ';
cout << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test;cin >> test;
while(test--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
3164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3416 KB |
Output is correct |
2 |
Correct |
11 ms |
3676 KB |
Output is correct |
3 |
Correct |
10 ms |
3676 KB |
Output is correct |
4 |
Correct |
12 ms |
3672 KB |
Output is correct |
5 |
Correct |
11 ms |
3672 KB |
Output is correct |
6 |
Correct |
8 ms |
3420 KB |
Output is correct |
7 |
Correct |
16 ms |
3524 KB |
Output is correct |
8 |
Correct |
10 ms |
3932 KB |
Output is correct |
9 |
Correct |
11 ms |
4188 KB |
Output is correct |
10 |
Correct |
13 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
3164 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |