Submission #69964

#TimeUsernameProblemLanguageResultExecution timeMemory
69964khohkoparentrises (BOI18_parentrises)C++17
50 / 100
161 ms13336 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; #define ll long long #define pb push_back #define fr first #define sc second #define MAX ((ll)(1e12+100)) #define MX ((ll)(1e6+100)) #define ARRS ((ll)(2e5+100)) #define HS ((ll)(233)) #define MOD ((ll)(1e9+7)) #define EP ((double)(1e-9)) #define LG 21 #define mul(a,b) a=((a)*(b))%MOD using namespace std; int main(){ #ifdef KHOKHO freopen("in.in","r",stdin); freopen("out.out","w",stdout); #endif // KHOKHO ios::sync_with_stdio(0); ll q,n; string s; string pas; cin>>q>>q; while(q--){ cin>>s; pas=s; n=s.size(); for(int i=0; i<n; i++)pas[i]='G'; stack<ll> sk; ll ca=0,cb=0,cr=0; bool e=1; for(int i=0; i<n; i++){ if(s[i]=='(')ca++; else cb++; if(2*ca<cb){e=0;break;} if(s[i]==')'){ cr++; if(cr>ca){ cr--; pas[i]='R'; pas[sk.top()]='B'; sk.pop(); } else sk.push(i); } } ca=cb=cr=0; while(sk.size())sk.pop(); for(int i=n-1; i>=0; i--){ if(s[i]=='(')ca++; else cb++; if(2*cb<ca){e=0;break;} if(s[i]=='('){ cr++; if(cr>cb){ cr--; pas[i]='B'; pas[sk.top()]='R'; sk.pop(); } else sk.push(i); } } //cout<<e<<endl; if(!e)cout<<"impossible"<<endl; else cout<<pas<<endl; } }
#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...