#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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
472 KB |
Output is correct |
17 |
Correct |
5 ms |
1108 KB |
Output is correct |
18 |
Correct |
4 ms |
588 KB |
Output is correct |
19 |
Correct |
4 ms |
880 KB |
Output is correct |
20 |
Correct |
4 ms |
1108 KB |
Output is correct |
21 |
Correct |
45 ms |
2032 KB |
Output is correct |
22 |
Correct |
38 ms |
7272 KB |
Output is correct |
23 |
Correct |
30 ms |
2700 KB |
Output is correct |
24 |
Correct |
41 ms |
4120 KB |
Output is correct |
25 |
Correct |
41 ms |
7272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |