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;
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 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... |