#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 200005
const int M = 1e9 + 7;
using namespace std;
int t, n, xd[maxn], ans[maxn];
string s;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp", "r")){
freopen(Alora".inp", "r", stdin);
freopen(Alora".out", "w", stdout);}
cin >> t;
while(t--){
cin >> n;
cin >> s; s = ' ' + s;
fi(i, 1, 2*n) xd[i] = 0, ans[i] = 0;
fi(i, 1, n){
int a, b; cin >> a >> b;
if(s[a] == '(') ans[i] = 0, xd[a] = 1;
else ans[i] = 1, xd[b] = 1;
}
if(n % 2 == 1) {cout << -1 << '\n'; continue;}
int A = 0;
fi(i, 1, 2*n) if(xd[i]){
if(s[i] == '(') A++;
else A--;
if(A < 0) break;
}
if(A != 0) {cout << -1 << '\n'; continue;}
fi(i, 1, n) cout << ans[i] << " ";
cout << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(Alora".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(Alora".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1112 KB |
Output is correct |
2 |
Correct |
14 ms |
1628 KB |
Output is correct |
3 |
Correct |
11 ms |
1884 KB |
Output is correct |
4 |
Correct |
13 ms |
2272 KB |
Output is correct |
5 |
Correct |
12 ms |
2368 KB |
Output is correct |
6 |
Correct |
10 ms |
2136 KB |
Output is correct |
7 |
Correct |
9 ms |
2392 KB |
Output is correct |
8 |
Correct |
11 ms |
2716 KB |
Output is correct |
9 |
Correct |
12 ms |
3144 KB |
Output is correct |
10 |
Correct |
14 ms |
3448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
1116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |