# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730727 | 2023-04-26T10:32:47 Z | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 24 ms | 396 KB |
#include<bits/stdc++.h> using namespace std; #define f first #define s second #define pf printf #define pii pair<int,int> pii ab[200001]; char naw[200001]; int jb[200001],gr[200001]; int t,n; void rozw() { scanf("%d",&n); priority_queue<pii ,vector<pii >,greater<pii >>dod; getchar(); for(int i=0;i<n*2;++i) naw[i]=getchar(); for(int i=0;i<n;++i) { scanf("%d%d",&ab[i].f,&ab[i].s); gr[ab[i].f]=--ab[i].s; gr[ab[i].s]=--ab[i].f; } int ile=0; for(int i=0;i<2*n;++i) { if(naw[gr[i]]==naw[i]) { if(naw[i]=='('&&i<gr[i]) { jb[i]=t; jb[gr[i]]=-t; ++ile; } else if(naw[i]==')'&&i>gr[i]) { jb[i]=t; jb[gr[i]]=-t; --ile; } } else { if(jb[i]!=-t&&jb[i]!=t) { if(naw[i]=='(') { jb[i]=-t; jb[gr[i]]=t; dod.push({gr[i],i}); } else { jb[i]=t; jb[gr[i]]=-t; --ile; dod.push({gr[i],i}); } } else if(jb[i]==t) { ile++; if(naw[i]==')') ile-=2; } } if(ile<0) { if(dod.empty()) { pf("-1\n"); return; } jb[dod.top().s]*=-1; jb[dod.top().f]*=-1; ++ile; if(max(dod.top().f,dod.top().s)<=i) ++ile; dod.pop(); } } if(ile!=0) { pf("-1\n"); return; } for(int i=0;i<n;++i) { if(jb[ab[i].f]==t) pf("0 "); else pf("1 "); } pf("\n"); } int main() { scanf("%d",&t); while(t) { rozw(); --t; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 380 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |