Submission #847167

#TimeUsernameProblemLanguageResultExecution timeMemory
847167PacybwoahSuperpozicija (COCI22_superpozicija)C++17
20 / 110
18 ms3548 KiB
#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> prov(n),ans(n); sort(vec.begin(),vec.end()); int left=0,right=0; for(int i=0;i<n;i++){ if(s[vec[i].first]==s[vec[i].second]){ if(s[vec[i].first]=='(') prov[i]=1,left++; else prov[i]=-1,right++; } } if(left>n/2||right>n/2){ cout<<"-1\n"; continue; } int cnt=0; for(int i=0;i<n;i++){ if(prov[i]==0){ if(cnt<n/2-left){ cnt++; prov[i]=1; } else prov[i]=-1; } } int now=0; bool flag=1; for(int i=0;i<n;i++){ if(prov[i]==1){ if(s[vec[i].first]=='(') ans[i]=0; else ans[i]=1; now++; } else{ if(s[vec[i].second]==')') ans[i]=1; else ans[i]=0; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...