#pragma GCC optimize("O4,unroll-loops")
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define endl "\n"
#define mp make_pair
#define out(x) cout << #x << " = " << x << endl
int n,a[200005], b[200005], arr[200005];
string s;
void solve(){
cin>>n>>s;
for (int i=1;i<=n*2;i++) s[i-1] == '(' ? arr[i] = 1 : arr[i] = -1;
for (int i=1;i<=n;i++) cin>>a[i]>>b[i];
if (n&1){
cout<<-1<<endl; return;
}
if (n<=10){
int flag = false;
for (int bit=0;bit<(1<<n);bit++){
set<int> st;
for (int i=0;i<n;i++) {
if ((bit >> i) & 1) st.insert(b[i+1]);
else st.insert(a[i+1]);
}
int now = 0;
for (int u:st){
now += arr[u];
if (now < 0) break;
}
if (now==0){
for (int i=0;i<n;i++) cout<<((bit>>i) & 1)<<" "[i==(n-1)];
//cout<<endl;
flag = true;
break;
}
}
if (!flag) cout<<-1<<endl;
}
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t; cin>>t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
583 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
583 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |