제출 #853109

#제출 시각아이디문제언어결과실행 시간메모리
853109sofijavelkovska중앙값 배열 (balkan11_medians)C++17
5 / 100
89 ms12884 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, lb, ub, x, y, i; set<int> notused; cin >> n; int a[2*n-1], b[n]; for (i=0; i<n; i++) cin >> b[i]; for (i=1; i<=2*n-1; i++) notused.insert(i); a[0]=b[0]; notused.erase(b[0]); for (i=1; i<n; i++) { if (i==n-1) { lb=b[i]; ub=b[i]; } else { if (b[i+1]<b[i]) { lb=b[i+1]; ub=b[i]; } else { lb=b[i]; ub=b[i+1]; } } if (b[i]==b[i-1]) { auto it=notused.lower_bound(max(b[i], ub)); x=*it; notused.erase(x); it=notused.upper_bound(min(b[i], lb)); it--; y=*it; notused.erase(y); } if (b[i]>b[i-1]) { auto it=notused.lower_bound(max(b[i], ub)); x=*it; it++; y=*it; notused.erase(x); notused.erase(y); } if (b[i]<b[i-1]) { auto it=notused.upper_bound(min(b[i], ub)); it--; x=*it; it--; y=*it; notused.erase(x); notused.erase(y); } a[2*i-1]=x; a[2*i]=y; } for (i=0; i<2*n-1; i++) cout << a[i] << " "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...