Submission #730711

#TimeUsernameProblemLanguageResultExecution timeMemory
730711AugustynSuperpozicija (COCI22_superpozicija)C++17
110 / 110
29 ms4400 KiB
#include<iostream> #include<vector> #include<queue> using namespace std; vector<pair<int,int>>ab; vector<char>naw; vector<int>juzwyb,gdziedr; int t,n; void rozw() { scanf("%d",&n); priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod; ab.resize(n); juzwyb.resize(n<<1); gdziedr.resize(n<<1); naw.resize(n<<1); char wcz=getchar(); while(wcz!='('&&wcz!=')') wcz=getchar(); for(int i=0;i<(n<<1);++i) { naw[i]=wcz; wcz=getchar(); } for(int i=0;i<n;++i) { scanf("%d%d",&ab[i].first,&ab[i].second); --ab[i].first; --ab[i].second; gdziedr[ab[i].first]=ab[i].second; gdziedr[ab[i].second]=ab[i].first; } int ile=0; for(int i=0;i<2*n;++i) { if(naw[gdziedr[i]]==naw[i]) { if(naw[i]=='('&&i<gdziedr[i]) { juzwyb[i]=t; juzwyb[gdziedr[i]]=-t; ++ile; } else if(naw[i]==')'&&i>gdziedr[i]) { juzwyb[i]=t; juzwyb[gdziedr[i]]=-t; --ile; } } else { if(juzwyb[i]!=-t&&juzwyb[i]!=t) { if(naw[i]=='(') { juzwyb[i]=-t; juzwyb[gdziedr[i]]=t; dod.push({gdziedr[i],i}); } else { juzwyb[i]=t; juzwyb[gdziedr[i]]=-t; --ile; dod.push({gdziedr[i],i}); } } else { if(juzwyb[i]==t) { if(naw[i]==')') --ile; else ++ile; } } } if(ile<0) { if(dod.empty()) { printf("-1\n"); return; } juzwyb[dod.top().second]*=-1; juzwyb[dod.top().first]*=-1; ++ile; if(max(dod.top().first,dod.top().second)<=i) ++ile; dod.pop(); } } if(ile!=0) { printf("-1\n"); return; } for(int i=0;i<n;++i) { if(juzwyb[ab[i].first]==t) printf("0 "); else printf("1 "); } printf("\n"); } int main() { ios_base::sync_with_stdio(0); scanf("%d",&t); while(t) { rozw(); --t; } }

Compilation message (stderr)

Main.cpp: In function 'void rozw()':
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d%d",&ab[i].first,&ab[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     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...