#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[100005], b[100005], arr[100005];
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];
int flag = false;
if (n<=10){
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 |
553 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
553 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |