#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int l[maxn], r[maxn];
int main(){
ios_base::sync_with_stdio(false);
int type;
cin >> type;
if (type == 1){
int tc;
cin >> tc;
while (tc --){
string s;
cin >> s;
int L = 0, R = 0;
int n = s.size();
bool flag = 0;
for (int i = n-1; i >= 0; i--){
if (s[i] == ')')
L ++, R += 2;
else{
if (R == 0){
flag = 1;
break;
}
L = max(0, L-2);
R --;
}
l[i] = L, r[i] = R;
}
if (flag == 1 or L > 0){
cout << "impossible\n";
continue;
}
l[n] = r[n] = 0;
int now = 0;
bool Red1 = 1, Red2 = 1;
for (int i = 0; i < n; i++){
if (s[i] == '('){
if (l[i+1] <= now+1 and now+1 <= r[i+1]){
if (Red1)
cout << 'R';
else
cout << 'B';
Red1 ^= 1;
now ++;
}
else{
cout << 'G';
now += 2;
}
}
else{
if (l[i+1] <= now-1 and now-1 <= r[i+1]){
if (Red2)
cout << 'R';
else
cout << 'B';
Red2 ^= 1;
now --;
}
else{
cout << 'G';
now -= 2;
}
}
}
cout << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
18 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
1536 KB |
Output is correct |
18 |
Correct |
3 ms |
640 KB |
Output is correct |
19 |
Correct |
4 ms |
1024 KB |
Output is correct |
20 |
Correct |
6 ms |
1536 KB |
Output is correct |
21 |
Correct |
151 ms |
2168 KB |
Output is correct |
22 |
Correct |
47 ms |
11284 KB |
Output is correct |
23 |
Correct |
30 ms |
3116 KB |
Output is correct |
24 |
Correct |
38 ms |
6228 KB |
Output is correct |
25 |
Correct |
47 ms |
11284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Unexpected end of file - int32 expected |