#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define all(x) x.begin(),x.end()
int trans(char a){
return (a=='('?1:-1);
}
void solve(){
int n;
cin>>n;
string str;
cin>>str;
vector<pair<int,int>> num(n);
for(int i=0;i<n;i++){
cin>>num[i].f>>num[i].s;
num[i].f--;
num[i].s--;
}
for(int i=0;i<(1<<n);i++){
vector<int> ans;
vector<pair<int,int>> cur;
for(int j=0;j<n;j++){
if(i&(1<<j)){
ans.push_back(1);
cur.push_back({num[j].s,trans(str[num[j].s])});
}
else{
ans.push_back(0);
cur.push_back({num[j].f,trans(str[num[j].f])});
}
}
sort(all(cur));
bool tf=true;
int cnt=0;
for(int i=0;i<n;i++){
cnt+=cur[i].s;
if(cnt<0) tf=false;
}
if(tf and cnt==0){
for(int i=0;i<n;i++){
cout<<ans[i]<<' ';
}
return;
}
}
cout<<-1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
cout<<'\n';
}
cout<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
458 ms |
464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
304 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 |
458 ms |
464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |