제출 #1151053

#제출 시각아이디문제언어결과실행 시간메모리
1151053vpinxmedians (balkan11_medians)C++20
15 / 100
1096 ms960 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, num; bool seen = 0, switched = 0; vector<int> b, ans; cin >> n; for(int i = 0; i < n; i++) { cin >> num; b.push_back(num); } for(int i = 0; i < n; i++) { int small = 1, big = 2 * n - 1, smaller = 0, bigger = 0, switched = 0, seen = 0; ans.push_back(b[i]); if(i != 0){ for(int j = 0; j < ans.size(); j++){ if(ans[j] != b[i]) { if(ans[j] < b[i]) smaller++; else bigger++; }else if(seen){ ans.erase(ans.begin() + j); seen = 0; switched = 1; }else seen = 1; } vector<int> x = ans; sort(x.begin(), x.end()); for(int j = 0; j < x.size(); j++) if(small == x[j]) small++; sort(x.begin(), x.end(), greater<>()); for(int j = 0; j < x.size(); j++) if(big == x[j]) big--; if(switched){ if(small != big){ ans.push_back(small); ans.push_back(big); small++; big--; }else{ ans.push_back(small); small++; } }else{ if(smaller < bigger){ ans.push_back(small); small++; }else{ ans.push_back(big); big--; } } } } for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...