This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
vector<pair<int,int> > vec(n);
for(int i=0;i<n;i++) cin>>vec[i].first>>vec[i].second,vec[i].first--,vec[i].second--;
if(n&1){
cout<<"-1\n";
continue;
}
vector<int> ans(n),pos;
for(int i=0;i<n;i++){
if(s[vec[i].first]=='('){
pos.push_back(vec[i].first);
ans[i]=0;
}
else{
pos.push_back(vec[i].second);
ans[i]=1;
}
}
sort(pos.begin(),pos.end());
int now=0;
bool flag=1;
for(int i=0;i<n;i++){
if(s[pos[i]]=='('){
now++;
}
else now--;
if(now<0){
flag=0;
break;
}
}
if(flag&&now==0){
for(auto x:ans) cout<<x<<" ";
cout<<"\n";
}
else cout<<"-1\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |