# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248666 | thebes | parentrises (BOI18_parentrises) | C++14 | 0 ms | 256 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 <bits/stdc++.h>
using namespace std;
const int MN = 1e6+6, MM = 303;
int S, T, N, i, j, w[MN], cur, fl;
string s; stack<int> go;
int main(){
scanf("%d",&S);
if(S==1){
scanf("%d",&T);
while(T--){
cin >> s; N = (int)s.size();
for(i=1;i<=N;i++) w[i]=1;
while(go.size()) go.pop();
cur = fl = 0;
for(i=0;i<N;i++){
if(s[i]=='('){
cur++;
go.push(i);
}
else if(cur) cur--;
else{
if(go.empty()){
fl=1;
break;
}
w[go.top()]=2;
go.pop();
}
}
while(go.size()) go.pop();
cur = 0;
for(i=N-1;i>=0;i--){
if(s[i]==')'){
cur++;
go.push(i);
}
else if(cur>=w[i]) cur-=w[i];
else{
int r = cur;
cur = 0;
while(r<w[i]){
if(go.empty()){
fl=1;
break;
}
r++;
w[go.top()]=2;
go.pop();
}
}
}
if(fl) printf("impossible\n");
else{
int hm = 0;
for(i=0;i<N;i++){
if(w[i]==2) printf("G");
else printf("%c","BR"[hm]), hm=!hm;
}
printf("\n");
}
}
}
}
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... |