Submission #248666

#TimeUsernameProblemLanguageResultExecution timeMemory
248666thebesparentrises (BOI18_parentrises)C++14
0 / 100
0 ms256 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 1e6+6, MM = 303; int S, T, N, i, j, w[MN], cur, fl; string s; stack<int> go; int main(){ scanf("%d",&S); if(S==1){ scanf("%d",&T); while(T--){ cin >> s; N = (int)s.size(); for(i=1;i<=N;i++) w[i]=1; while(go.size()) go.pop(); cur = fl = 0; for(i=0;i<N;i++){ if(s[i]=='('){ cur++; go.push(i); } else if(cur) cur--; else{ if(go.empty()){ fl=1; break; } w[go.top()]=2; go.pop(); } } while(go.size()) go.pop(); cur = 0; for(i=N-1;i>=0;i--){ if(s[i]==')'){ cur++; go.push(i); } else if(cur>=w[i]) cur-=w[i]; else{ int r = cur; cur = 0; while(r<w[i]){ if(go.empty()){ fl=1; break; } r++; w[go.top()]=2; go.pop(); } } } if(fl) printf("impossible\n"); else{ int hm = 0; for(i=0;i<N;i++){ if(w[i]==2) printf("G"); else printf("%c","BR"[hm]), hm=!hm; } printf("\n"); } } } }

Compilation message (stderr)

parentrises.cpp: In function 'int main()':
parentrises.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&S);
     ~~~~~^~~~~~~~~
parentrises.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...