#include <stdio.h>
#include <stdbool.h>
#define MAXN 100100
#define update_min() while(used[++minimum])
#define update_max() while(used[--maximum])
int main(void) {
static int n, a[MAXN], b[MAXN];
static bool used[2 * MAXN];
scanf("%d", &n);
int minimum = 0, maximum = 2 * n;
used[2 * n] = true;
used[0] = true;
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
a[1] = b[1];
for(int i = 2; i <= n; i++) {
if(b[i] == b[i - 1]) {
update_min();
a[2 * i - 2] = minimum, used[minimum] = true;
update_max();
a[2 * i - 1] = maximum, used[maximum] = true;
}
if(b[i] > b[i - 1]) {
if(used[b[i]] == false) {
a[2 * i - 2] = b[i];
used[b[i]] = true;
update_max();
a[2 * i - 1] = maximum, used[maximum] = true;
} else {
update_max();
a[2 * i - 2] = maximum, used[maximum] = true;
update_max();
a[2 * i - 1] = maximum, used[maximum] = true;
}
}
if(b[i] < b[i - 1]) {
if(used[b[i]] == false) {
a[2 * i - 2] = b[i], used[b[i]] = true;
update_min();
a[2 * i - 1] = minimum, used[minimum] = true;
} else {
update_min();
a[2 * i - 2] = minimum, used[minimum] = true;
update_min();
a[2 * i - 1] = minimum, used[minimum] = true;
}
}
}
printf("%d", a[1]);
for(int i = 2; i < 2 * n; i++) printf(" %d", a[i]);
return 0;
}
Compilation message
medians.c: In function 'main':
medians.c:9:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
medians.c:13:30: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
2 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
3 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
4 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
5 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
6 |
Correct |
0 ms |
2092 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
8 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
9 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
10 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
11 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
12 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
13 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
2 |
Incorrect |
0 ms |
2092 KB |
Not a permutation |
3 |
Incorrect |
3 ms |
2092 KB |
Not a permutation |
4 |
Incorrect |
3 ms |
2092 KB |
Not a permutation |
5 |
Incorrect |
6 ms |
2092 KB |
Not a permutation |
6 |
Incorrect |
19 ms |
2092 KB |
Not a permutation |
7 |
Incorrect |
33 ms |
2092 KB |
Not a permutation |