Submission #51808

#TimeUsernameProblemLanguageResultExecution timeMemory
51808someone_aamedians (balkan11_medians)C++17
85 / 100
34 ms3472 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100100; int a[2*maxn], b[maxn], n; int minvalue, maxvalue; bool visited[2*maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>b[i]; } minvalue = 1; maxvalue = 2*n-1; visited[b[1]]=true; a[1] = b[1]; while(visited[minvalue]) minvalue++; while(visited[maxvalue]) maxvalue--; for(int i=2;i<=n;i++) { if(b[i] == b[i-1]) { a[2*(i-1)] = minvalue; visited[minvalue] = true; while(visited[minvalue]) minvalue++; a[2*(i-1)+1] = maxvalue; visited[maxvalue] = true; while(visited[maxvalue]) maxvalue--; } else if(b[i] < b[i-1]) { if(visited[b[i]]) { a[2*(i-1)] = minvalue; visited[minvalue] = true; while(visited[minvalue]) minvalue++; a[2*(i-1)+1] = minvalue; visited[minvalue] = true; while(visited[minvalue]) minvalue++; } else { a[2*(i-1)] = b[i]; visited[b[i]] = true; while(visited[minvalue]) minvalue++; a[2*(i-1)+1] = minvalue; visited[minvalue] = true; while(visited[minvalue]) minvalue++; } } else if(b[i] > b[i-1]) { if(visited[b[i]]) { a[2*(i-1)] = maxvalue; visited[maxvalue] = true; while(visited[maxvalue]) maxvalue--; a[2*(i-1)+1] = maxvalue; visited[maxvalue] = true; while(visited[maxvalue]) maxvalue--; } else { a[2*(i-1)] = b[i]; visited[b[i]] = true; while(visited[maxvalue]) maxvalue--; a[2*(i-1)+1] = maxvalue; visited[maxvalue] = true; while(visited[maxvalue]) maxvalue--; } } } for(int i=1;i<=2*n-1;i++) { cout<<a[i]<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...