# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29205 | 2017-07-18T16:15:47 Z | Nirjhor | medians (balkan11_medians) | C++14 | 33 ms | 3604 KB |
#include <bits/stdc++.h> using namespace std; const int N = 200010; bitset <N> vis; int n, a[N], b[N], l, r; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", b + i); } a[1] = b[1]; l = 0, r = n + n; vis[b[1]] = vis[l] = vis[r] = 1; for (int i = 2, j = 2; i <= n; ++i, j += 2) { if (b[i] == b[i - 1]) { while (vis[l]) ++l; while (vis[r]) --r; a[j] = l, a[j + 1] = r; vis[l] = vis[r] = 1; } if (b[i] < b[i - 1]) { if (vis[b[i]]) { while (vis[l]) ++l; a[j] = l, vis[l] = 1; while (vis[l]) ++l; a[j + 1] = l, vis[l] = 1; } else { a[j] = b[i], vis[b[i]] = 1; while (vis[l]) ++l; a[j + 1] = l, vis[l] = 1; } } if (b[i] > b[i - 1]) { if (vis[b[i]]) { while (vis[r]) --r; a[j] = r, vis[r] = 1; while (vis[r]) --r; a[j + 1] = r, vis[r] = 1; } else { a[j] = b[i], vis[b[i]] = 1; while (vis[r]) --r; a[j + 1] = r, vis[r] = 1; } } } for (int i = 1; i < n + n; ++i) { printf("%d ", a[i]); } puts(""); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3604 KB | Output is correct |
2 | Correct | 0 ms | 3604 KB | Output is correct |
3 | Correct | 0 ms | 3604 KB | Output is correct |
4 | Correct | 0 ms | 3604 KB | Output is correct |
5 | Correct | 0 ms | 3604 KB | Output is correct |
6 | Correct | 0 ms | 3604 KB | Output is correct |
7 | Correct | 0 ms | 3604 KB | Output is correct |
8 | Correct | 0 ms | 3604 KB | Output is correct |
9 | Correct | 0 ms | 3604 KB | Output is correct |
10 | Correct | 0 ms | 3604 KB | Output is correct |
11 | Correct | 0 ms | 3604 KB | Output is correct |
12 | Correct | 0 ms | 3604 KB | Output is correct |
13 | Correct | 0 ms | 3604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3604 KB | Output is correct |
2 | Correct | 0 ms | 3604 KB | Output is correct |
3 | Correct | 0 ms | 3604 KB | Output is correct |
4 | Correct | 6 ms | 3604 KB | Output is correct |
5 | Correct | 6 ms | 3604 KB | Output is correct |
6 | Correct | 13 ms | 3604 KB | Output is correct |
7 | Correct | 33 ms | 3604 KB | Output is correct |