Submission #544743

#TimeUsernameProblemLanguageResultExecution timeMemory
544743rainboyparentrises (BOI18_parentrises)C11
0 / 100
0 ms296 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...