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;
#define ar array
typedef int64_t ll;
namespace S1{
const int N = 1e6 + 5;
void solve(){
string s; cin >> s;
int n = s.size();
vector<int> p, is(n);
for(int i=0;i<n;i++){
int v = (s[i] == ')');
if(v && !p.empty()){
is[p.back()] = is[i] = 1;
p.pop_back();
} else if(!v) {
p.push_back(i);
}
}
deque<int> q;
for(int i=0;i<n;i++){
if(!is[i]) q.push_back(i);
}
for(int i=0;i<n && !q.empty();i++){
if(!is[i]) continue;
if(s[q.front()] == ')'){
if(s[i] == '(' && i < q.front()){
is[i] = 2;
q.pop_front();
}
} else {
if(s[i] == ')' && i > q.front()){
is[i] = 2;
q.pop_front();
}
}
}
if(!q.empty()){
cout<<"impossible\n";
return;
}
for(int i=0;i<n;i++){
if(is[i] == 0) cout<<"R";
if(is[i] == 1) cout<<"B";
if(is[i] == 2) cout<<"G";
} cout<<"\n";
}
void main(){
int t; cin >> t;
while(t--){
solve();
}
}
};
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int T; cin >> T;
if(T == 1){
S1::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... |