#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n;
string s;
int p[N];
pair<int, int> a[N];
int ans[N], d[N], id[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--){
cin >> n >> s;
s=" "+s;
vector<int> vv;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int i=1; i<=n; ++i){
cin >> a[i].first >> a[i].second;
p[a[i].first]=a[i].second;
p[a[i].second]=a[i].first;
id[a[i].first]=id[a[i].second]=i;
if (s[a[i].first]==s[a[i].second]){
if (s[a[i].first]=='('){
ans[i]=0;
++d[a[i].first];
}else{
ans[i]=1;
--d[a[i].second];
}
}else{
if (s[a[i].first]=='('){
ans[i]=1;
--d[a[i].second];
}else{
ans[i]=0;
--d[a[i].first];
}
}
}
int pf=0;
for (int i=1; i<=n*2; ++i){
if (p[i]>i && s[i]!=s[p[i]]) pq.emplace(p[i], id[i]);
pf+=d[i];
if (pf<0){
if (pq.empty()) break;
auto tt=pq.top(); pq.pop();
ans[tt.second]^=1;
if (tt.first<=i) pf+=2;
else ++pf, ++d[tt.first];
}
}
if (pf) cout << -1 << '\n';
else{
for (int i=1; i<=n; ++i) cout << ans[i] << " \n"[i==n];
}
for (int i=1; i<=n*2; ++i) d[i]=0;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4696 KB |
Output is correct |
2 |
Correct |
13 ms |
4444 KB |
Output is correct |
3 |
Correct |
16 ms |
4700 KB |
Output is correct |
4 |
Correct |
16 ms |
4708 KB |
Output is correct |
5 |
Correct |
16 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4440 KB |
Output is correct |
2 |
Correct |
10 ms |
4444 KB |
Output is correct |
3 |
Correct |
9 ms |
4820 KB |
Output is correct |
4 |
Correct |
11 ms |
4916 KB |
Output is correct |
5 |
Correct |
12 ms |
4940 KB |
Output is correct |
6 |
Correct |
7 ms |
4980 KB |
Output is correct |
7 |
Correct |
10 ms |
4948 KB |
Output is correct |
8 |
Correct |
10 ms |
4956 KB |
Output is correct |
9 |
Correct |
11 ms |
5192 KB |
Output is correct |
10 |
Correct |
13 ms |
5216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
15 ms |
4596 KB |
Output is correct |
3 |
Correct |
13 ms |
4752 KB |
Output is correct |
4 |
Correct |
12 ms |
4788 KB |
Output is correct |
5 |
Correct |
14 ms |
4956 KB |
Output is correct |
6 |
Correct |
15 ms |
5040 KB |
Output is correct |
7 |
Correct |
6 ms |
4952 KB |
Output is correct |
8 |
Correct |
15 ms |
5208 KB |
Output is correct |
9 |
Correct |
10 ms |
5236 KB |
Output is correct |
10 |
Correct |
15 ms |
5540 KB |
Output is correct |
11 |
Correct |
17 ms |
5720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4696 KB |
Output is correct |
2 |
Correct |
13 ms |
4444 KB |
Output is correct |
3 |
Correct |
16 ms |
4700 KB |
Output is correct |
4 |
Correct |
16 ms |
4708 KB |
Output is correct |
5 |
Correct |
16 ms |
4700 KB |
Output is correct |
6 |
Correct |
10 ms |
4440 KB |
Output is correct |
7 |
Correct |
10 ms |
4444 KB |
Output is correct |
8 |
Correct |
9 ms |
4820 KB |
Output is correct |
9 |
Correct |
11 ms |
4916 KB |
Output is correct |
10 |
Correct |
12 ms |
4940 KB |
Output is correct |
11 |
Correct |
7 ms |
4980 KB |
Output is correct |
12 |
Correct |
10 ms |
4948 KB |
Output is correct |
13 |
Correct |
10 ms |
4956 KB |
Output is correct |
14 |
Correct |
11 ms |
5192 KB |
Output is correct |
15 |
Correct |
13 ms |
5216 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
15 ms |
4596 KB |
Output is correct |
18 |
Correct |
13 ms |
4752 KB |
Output is correct |
19 |
Correct |
12 ms |
4788 KB |
Output is correct |
20 |
Correct |
14 ms |
4956 KB |
Output is correct |
21 |
Correct |
15 ms |
5040 KB |
Output is correct |
22 |
Correct |
6 ms |
4952 KB |
Output is correct |
23 |
Correct |
15 ms |
5208 KB |
Output is correct |
24 |
Correct |
10 ms |
5236 KB |
Output is correct |
25 |
Correct |
15 ms |
5540 KB |
Output is correct |
26 |
Correct |
17 ms |
5720 KB |
Output is correct |
27 |
Correct |
22 ms |
4700 KB |
Output is correct |
28 |
Correct |
17 ms |
4700 KB |
Output is correct |
29 |
Correct |
16 ms |
4956 KB |
Output is correct |
30 |
Correct |
19 ms |
5108 KB |
Output is correct |
31 |
Correct |
17 ms |
5104 KB |
Output is correct |
32 |
Correct |
11 ms |
5208 KB |
Output is correct |
33 |
Correct |
14 ms |
5340 KB |
Output is correct |
34 |
Correct |
18 ms |
5464 KB |
Output is correct |
35 |
Correct |
18 ms |
5700 KB |
Output is correct |
36 |
Correct |
23 ms |
5688 KB |
Output is correct |