/**
* author: wxhtzdy
* created: 17.08.2022 19:58:30
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
string s;
cin >> s;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
--a[i]; --b[i];
}
string str = string(n, '?');
for (int i = 0; i < n; i++) {
if (s[a[i]] == s[b[i]]) {
str[i] = s[a[i]];
}
}
vector<int> mn(n + 1);
for (int i = n - 1; i >= 0; i--) {
int x = 0;
if (str[i] == '(') {
x = +1;
}
if (str[i] == ')') {
x = -1;
}
mn[i] = min(x, x + mn[i + 1]);
}
int bal = 0;
for (int i = 0; i < n; i++) {
if (str[i] == '(') {
bal += 1;
continue;
}
if (str[i] == ')') {
bal -= 1;
continue;
}
if (bal > 0 && bal + mn[i + 1] > 0) {
str[i] = ')';
bal -= 1;
} else {
str[i] = '(';
bal += 1;
}
}
if (bal == 0) {
for (int i = 0; i < n; i++) {
if (str[i] == s[a[i]]) {
cout << 0 << " ";
} else {
cout << 1 << " ";
}
}
cout << '\n';
} else {
cout << -1 << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
1172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
1172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |