제출 #656476

#제출 시각아이디문제언어결과실행 시간메모리
656476MilosMilutinovicZalmoxis (BOI18_zalmoxis)C++14
35 / 100
157 ms22344 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; auto Add = [&](int x) { vector<int> t(1, x); vector<int> f; while (!t.empty() && k > 0) { int x = t.back(); if (x > 1) { t.push_back(x - 1); t.push_back(x - 1); t.pop_back(); k--; } else { res.push_back(1); t.pop_back(); } } while (!t.empty()) { res.push_back(t.back()); t.pop_back(); } }; for (auto& p : ans) { if (p.second == 0) { Add(p.first); } else { res.push_back(p.first); } } for (auto& p : res) { cout << p << " "; } return 0; }

컴파일 시 표준 에러 (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...