This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,m,k,l,i,j,a,b,bal,li,ri,res[1000005];
string s;
vector<int>vl,vr;
main(){
int p;
cin>>p;
if(p==1)
{
int t;
cin>>t;
while(t--){
cin>>s;
n=s.size();
vl.clear();
vr.clear();bal=0;li=0;ri=0;
for(i=0;i<n;i++)res[i]=0;
for(i=0;i<n;i++){
if(s[i]=='(')
vl.push_back(i),bal++;
else
vr.push_back(i),bal--;
if(vr.size()>2*vl.size()) {cout<<"impossible"<<endl;break;}
if(bal<0){res[vl[li]]=3;li++;res[vr[ri]]=1;ri++;res[vr[ri]]=2;ri++;bal++;}
}
if(vr.size()>2*vl.size()) continue;
vl.clear();
vr.clear();bal=0;li=0;ri=0;
for(i=n-1;i>=0;i--){
if(res[i]!=0) continue;
if(s[i]==')')
vl.push_back(i),bal++;
else
vr.push_back(i),bal--;
if(vr.size()>2*vl.size()) {cout<<"impossible"<<endl;break;}
if(bal<0) {res[vl[li]]=3;li++;res[vr[ri]]=2;ri++;res[vr[ri]]=1;ri++;bal++;}
}
if(vr.size()>2*vl.size()) continue;
for(i=0;i<n;i++){
if(res[i]==0) cout<<"R";
if(res[i]==1) cout<<"R";
if(res[i]==2) cout<<"B";
if(res[i]==3) cout<<"G";
}
cout<<endl;
}}
}
Compilation message (stderr)
parentrises.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |