Submission #145000

#TimeUsernameProblemLanguageResultExecution timeMemory
145000MKopchevparentrises (BOI18_parentrises)C++14
50 / 100
238 ms6420 KiB
#include<bits/stdc++.h> using namespace std; const int nmax=1e6+42; char output[nmax]; stack<int> idle; int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); int p,t; cin>>p>>t; if(p==1) { string s; for(int i=1;i<=t;i++) { cin>>s; int SZ=s.size(); for(int j=0;j<SZ;j++) output[j]=-1; stack<int> open=idle; for(int j=0;j<SZ;j++) { if(s[j]=='(')open.push(j); else { if(open.size()) { output[open.top()]='R'; output[j]='R'; open.pop(); } } } bool ok=1; open=idle; for(int j=0;j<SZ;j++) { if(s[j]=='(')open.push(j); else { if(output[j]==-1) { if(open.size()==0)ok=0; else { output[j]='B'; output[open.top()]='G'; open.pop(); } } } } open=idle; for(int j=SZ-1;j>=0;j--) { if(s[j]==')')open.push(j); else { if(output[j]==-1) { if(open.size()==0)ok=0; else { output[j]='B'; output[open.top()]='G'; open.pop(); } } } } if(ok) { for(int j=0;j<SZ;j++)cout<<output[j]; cout<<endl; } else cout<<"impossible"<<endl; } } else { } return 0; }
#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...