Submission #774599

#TimeUsernameProblemLanguageResultExecution timeMemory
774599rainboyGood Game (CCO22_day2problem3)C11
0 / 25
0 ms288 KiB
#include <stdio.h> #define N 1000000 int main() { static char cc[N + 1]; static int ll[N], rr[N], ii[N], kk[N]; int n, m, cnt, h, h_, i, j, d, d_; scanf("%d%s", &n, cc); cnt = 0; while (n > 0) { m = 0; for (i = 0; i + 1 < n; i++) if (cc[i] == cc[i + 1]) { j = i + 1; while (j < n && cc[j] == cc[i]) j++; ll[m] = i, rr[m] = j - 1, m++; i = j - 1; } if (m == 0) { printf("-1\n"); return 0; } d_ = -1, h_ = -2; for (h = -1; h < m; h++) { d = (h + 1 == m ? m : rr[h + 1]) - (h < 0 ? -1 : ll[h]); if (d_ < d) d_ = d, h_ = h; } if (h_ == -1) h_++; if (h_ == 0 && ll[h_] == 0 && m >= 2) h_++; if ((rr[h_] - ll[h_] + 1) % 2 == 0) { ii[cnt] = ll[h_], kk[cnt] = 2, cnt++; n -= 2; for (i = ll[h_]; i < n; i++) cc[i] = cc[i + 2]; cc[n] = 0; } else { ii[cnt] = ll[h_], kk[cnt] = 3, cnt++; n -= 3; for (i = ll[h_]; i < n; i++) cc[i] = cc[i + 3]; cc[n] = 0; } } printf("%d\n", cnt); for (h = 0; h < cnt; h++) printf("%d %d\n", ii[h] + 1, kk[h]); return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:10:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d%s", &n, 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...