Submission #1062341

#TimeUsernameProblemLanguageResultExecution timeMemory
1062341bachhoangxuanSuperpozicija (COCI22_superpozicija)C++17
10 / 110
16 ms4440 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5+5; int n,d[maxn],nxt[maxn],f[maxn],val[maxn]; char c[maxn]; void solve(){ cin >> n; for(int i=1;i<=2*n;i++){ cin >> c[i]; nxt[i]=val[i]=f[i]=0; } for(int i=1;i<=n;i++){ int a,b;cin >> a >> b; if(c[a]==c[b]){ if(c[a]=='(') d[i]=0,val[a]++; else d[i]=1,val[b]--; } else{ nxt[a]=b,f[a]=i; if(c[a]=='(') d[i]=1,val[b]--; else d[i]=0,val[a]--; } } priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; int cnt=0; for(int i=1;i<=2*n;i++){ if(f[i]) pq.push({nxt[i],f[i]}); cnt+=val[i]; if(cnt<0){ if(pq.empty()) break; auto [x,id]=pq.top();pq.pop(); d[id]^=1; if(x<=i) cnt+=2; else cnt+=1,val[x]--; } } if(cnt) cout << -1 << '\n'; else{ for(int i=1;i<=n;i++) cout << d[i] << ' '; cout << '\n'; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int test;cin >> test; while(test--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...