Submission #882269

#TimeUsernameProblemLanguageResultExecution timeMemory
882269rainboyDEL13 (info1cup18_del13)C11
100 / 100
9 ms1368 KiB
#include <stdio.h> #include <string.h> #define N 100000 int main() { int t; scanf("%d", &t); while (t--) { static int ii[N], pp[N + 1]; int n, m, k, h, i, j, l, r; scanf("%d%d", &n, &m); for (h = 0; h < m; h++) scanf("%d", &ii[h]), ii[h]--; memset(pp, -1, (n + 1) * sizeof *pp), pp[0] = -2; for (h = 0; h < m; h++) { l = h == 0 ? 0 : ii[h - 1] + 1, r = h + 1 == m ? n : ii[h + 1]; for (i = l; i < ii[h]; i++) if (pp[i] != -1) { for (j = ii[h] + 2; j <= r; j++) if (j % 2 == (h + 1) % 2) pp[j] = i; break; } if (pp[ii[h]] != -1) pp[ii[h] + 1] = ii[h]; } if (pp[n] == -1) { printf("-1\n"); continue; } printf("%d\n", (n - m) / 2); for (h = m - 1, r = n; h >= 0; h--) { l = pp[r], r--, i = ii[h]; if (i - l <= r - i) { k = (r + l) / 2 - i, j = i + k + 1; while (k--) printf("%d ", j + 1); k = i - l; while (k--) printf("%d ", i + 1); } else { k = i - (r + l) / 2, j = i - k - 1; while (k--) printf("%d ", j + 1); k = r - i; while (k--) printf("%d ", i + 1); } r = l; } printf("\n"); } return 0; }

Compilation message (stderr)

del13.c: In function 'main':
del13.c:9:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  scanf("%d", &t);
      |  ^~~~~~~~~~~~~~~
del13.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d%d", &n, &m);
      |   ^~~~~~~~~~~~~~~~~~~~~
del13.c:16:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |    scanf("%d", &ii[h]), ii[h]--;
      |    ^~~~~~~~~~~~~~~~~~~
#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...