Submission #1276927

#TimeUsernameProblemLanguageResultExecution timeMemory
1276927dqa중앙값 배열 (balkan11_medians)C++20
65 / 100
2 ms580 KiB
#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <numeric> #include <map> #include <sstream> #include <cstring> #include <stack> #include <climits> using namespace std; const long long INF = 1e9; int n; int b[2005]; vector<int> a; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // freopen("cowtip.in", "r", stdin); // freopen("cowtip.out", "w", stdout); int n; cin >> n; bool used[2005]; memset(used, false, sizeof(used)); for (int i = 1; i <= n; i++) { cin >> b[i]; } int m = 2*n - 1; int num = 1; for (int i = 1; i <= n; i++) { bool check = false; int higher = 0, lower = 0; int elements = 2 * i - 1; for(int x : a) { if (x > b[i]) { higher++; } else if (x < b[i]) { lower++; } } if(!used[b[i]]) { a.push_back(b[i]); used[b[i]] = true; } while((int)a.size() != elements) { if(lower > higher) { while(used[m] && m > 0) { m--; } a.push_back(m); used[m] = true; higher++; } else if (lower < higher) { while(used[num] && num <= m) { num++; } a.push_back(num); used[num] = true; lower++; } else if (lower == higher) { while(used[m] && m > 0) { m--; } a.push_back(m); used[m] = true; higher++; while(used[num] && num <= m) { num++; } a.push_back(num); used[num] = true; lower++; } } } for (auto v : a) { cout << v << " "; } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...