Submission #50233

#TimeUsernameProblemLanguageResultExecution timeMemory
50233rondojimmedians (balkan11_medians)C++17
100 / 100
38 ms3740 KiB
#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)

medians.cpp: In function 'int main()':
medians.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &N);
   ~~~~~^~~~~~~~~~
medians.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=1; i<=N; ++i) scanf("%d", &B[i]);
                           ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...