Submission #730738

#TimeUsernameProblemLanguageResultExecution timeMemory
730738AugustynSuperpozicija (COCI22_superpozicija)C++17
110 / 110
32 ms4424 KiB
#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); --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 (stderr)

Main.cpp: In function 'void rozw()':
Main.cpp:13:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | scanf("%d",&n);
      | ~~~~~^~~~~~~~~
Main.cpp:20:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 | scanf("%d%d",&ab[i].f,&ab[i].s);
      | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:100:6: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 | scanf("%d",&t);
      | ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...