Submission #656852

#TimeUsernameProblemLanguageResultExecution timeMemory
656852MilosMilutinovicZalmoxis (BOI18_zalmoxis)C++14
100 / 100
180 ms59244 KiB
#include <bits/stdc++.h> using namespace std; void Push(vector<int>& v) { while (v.size() >= 2) { int sz = (int) v.size(); if (v[sz - 1] == v[sz - 2]) { int x = v[sz - 1]; v.pop_back(); v.pop_back(); v.push_back(x + 1); } else { break; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } a.push_back(30); n++; vector<int> stk; vector<pair<int, int>> ans; for (int i = 0; i < n; i++) { while (!stk.empty() && stk.back() < a[i]) { int x = stk.back(); ans.emplace_back(stk.back(), 1); stk.push_back(stk.back()); Push(stk); } ans.emplace_back(a[i], 0); stk.push_back(a[i]); Push(stk); } ans.pop_back(); for (auto& p : ans) { k -= p.second; } vector<int> res; function<void(int)> Add = [&](int x) { if (x == 1 || k == 0) { res.push_back(x); } else { k--; Add(x - 1); Add(x - 1); } }; for (auto& p : ans) { if (p.second == 1) { Add(p.first); } else { res.push_back(p.first); } } for (auto& p : res) { cout << p << " "; } return 0; }

Compilation message (stderr)

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:34:11: warning: unused variable 'x' [-Wunused-variable]
   34 |       int x = stk.back();
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...