# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
50233 | rondojim | medians (balkan11_medians) | C++17 | 38 ms | 3740 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
const int MAXN = 2e5 + 5;
int vis[MAXN], minimum, maximum, A[MAXN], B[MAXN], N;
void plus(){ while(vis[minimum]) minimum++; }
void minus(){ while(vis[maximum]) maximum--; }
int main(){
scanf("%d", &N);
for(int i=1; i<=N; ++i) scanf("%d", &B[i]);
minimum = 0, maximum = 2 * N;
vis[minimum] = vis[maximum] = vis[B[1]] = 1, A[1] = B[1];
for(int i=2; i<=N; ++i){
if(B[i - 1] == B[i]){
plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
else if(B[i - 1] < B[i]){
if(!vis[B[i]]){
A[2 * i - 2] = B[i], vis[B[i]] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
else{
minus(); A[2 * i - 2] = maximum, vis[maximum] = 1;
minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
}
}
else if(B[i - 1] > B[i]){
if(!vis[B[i]]){
A[2 * i - 2] = B[i], vis[B[i]] = 1;
plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
}
else{
plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
}
}
}
for(int i=1; i<2*N; ++i) printf("%d ", A[i]);
puts("");
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |