Submission #1144421

#TimeUsernameProblemLanguageResultExecution timeMemory
1144421not_amirZalmoxis (BOI18_zalmoxis)C++20
100 / 100
84 ms10400 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; void print(int val, int cnt) { if (cnt == 1) cout << val << ' '; else print(val - 1, cnt / 2), print(val - 1, (cnt + 1) / 2); } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n, k; cin >> n >> k; stack<int> stk; vector<pair<int, bool>> ans; for (int i = 0; i < n; i++) { int x; cin >> x; int prev = -1; while (!stk.empty() && stk.top() < x) { if (prev == -1) prev = stk.top(); else { for (int idx = prev; idx < stk.top(); idx++) ans.push_back({idx, true}); prev = stk.top() + 1; } stk.pop(); } if (prev != -1) { for (int idx = prev; idx < x; idx++) ans.push_back({idx, true}); int tx = x; while (!stk.empty() && stk.top() == tx) { stk.pop(); tx++; } stk.push(tx); } ans.push_back({x, false}); while (!stk.empty() && stk.top() == x) { stk.pop(); x++; } stk.push(x); } int prev = -1; while (!stk.empty()) { if (prev == -1) prev = stk.top(); else { for (int idx = prev; idx < stk.top(); idx++) ans.push_back({idx, true}); prev = stk.top() + 1; } stk.pop(); } for (int idx = prev; idx < 30; idx++) ans.push_back({idx, true}); int lft = n + k - ans.size(); for (int i = 0; i < ans.size(); i++) { if (ans[i].second) { int cnt = min(1 << ans[i].first, lft + 1); lft -= cnt - 1; print(ans[i].first, cnt); } else cout << ans[i].first << ' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...