# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129197 | thanos | parentrises (BOI18_parentrises) | C++14 | 93 ms | 1272 KiB |
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<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
int P;
cin>>P;
if(P==2){
cout<<0<<endl;
return 0;
}
int T;
cin>>T;
for(int k=0; k<T; k++){
bool f=true;
string s;
int c[10005]={0};
stack<int> myst;
bool v[10005]={false},vv[100005]={false};
cin>>s;
for(int i=0; i<s.length(); i++){
if(s[i]=='('){
myst.push(i);
}
else{
if(!myst.empty()){
myst.pop();
}
else{
v[i]=vv[i]=true;
}
}
}
while(!myst.empty()){
v[myst.top()]=vv[myst.top()]=true;
myst.pop();
}
for(int i=0; i<s.length(); i++){
if(vv[i]){
bool g=false;
if(s[i]==')'){
int h=i-1;
while(h>=0){
if(s[h]==')' && !v[h]){
v[h]=true;
c[h]=1;
c[i]=2;
g=true;
break;
}
h--;
}
}
if(s[i]=='('){
int h=i+1;
while(h<s.length()){
if(s[h]=='(' && !v[h]){
v[h]=true;
c[h]=1;
c[i]=2;
g=true;
break;
}
h++;
}
}
if(!g){
cout<<"impossible"<<endl;
f=false;
break;
}
}
}
if(!f){
continue;
}
for(int i=0; i<s.length(); i++){
if(c[i]==0){
cout<<"G";
}
else if(c[i]==1){
cout<<"B";
}
else{
cout<<"R";
}
}
cout<<endl;
}
return 0;
}
Compilation message (stderr)
# | 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... |