#include <stdio.h>
#include <string.h>
#define N 1000000
int main() {
int t;
scanf("%d", &t);
while (t--) {
static char cc[N + 1], cc_[N + 1];
static int qu[N];
int n, i, d, cnt, bad;
scanf("%s", cc), n = strlen(cc);
memset(cc_, 0, (n + 1) * sizeof *cc_);
d = 0, cnt = 0, bad = 0;
for (i = 0; i < n; i++)
if (cc[i] == '(')
d++, qu[cnt++] = i;
else if (d-- == 0) {
if (cnt == 0) {
bad = 1;
break;
}
d = 0, cc_[qu[--cnt]] = 'G';
}
if (bad) {
printf("impossible\n");
continue;
}
d = 0, cnt = 0, bad = 0;
for (i = n - 1; i >= 0; i--)
if (cc[i] == ')')
d++, qu[cnt++] = i;
else {
if (d-- == 0) {
if (cnt == 0) {
bad = 1;
break;
}
d = 0, cc_[qu[--cnt]] = 'G';
}
if (cc_[i] == 'G' && d-- == 0) {
if (cnt == 0) {
bad = 1;
break;
}
d = 0, cc_[qu[--cnt]] = 'G';
}
}
if (bad) {
printf("impossible\n");
continue;
}
cnt = 0;
for (i = 0; i < n; i++)
if (cc_[i] == 'G')
cnt += cc[i] == '(' ? 2 : -2;
else
cc_[i] = (cc[i] == '(' ? cnt++ : --cnt) % 2 == 0 ? 'R' : 'B';
printf("%s\n", cc_);
}
return 0;
}
Compilation message
parentrises.c: In function 'main':
parentrises.c:9:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d", &t);
| ^~~~~~~~~~~~~~~
parentrises.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%s", cc), n = strlen(cc);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - token expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
296 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
296 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
296 KB |
Expected integer, but "impossible" found |
2 |
Halted |
0 ms |
0 KB |
- |