#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
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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
4 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
856 KB |
Output is correct |
9 |
Correct |
9 ms |
1012 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
9 ms |
1368 KB |
Output is correct |