Submission #1136394

#TimeUsernameProblemLanguageResultExecution timeMemory
1136394poatZalmoxis (BOI18_zalmoxis)C++20
0 / 100
926 ms110020 KiB
// #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define int long long // #define mkp make_pair #define txt freopen("kout.in", "r", stdin), freopen("kout.out", "w", stdout); const int N = 2000, K = 20; const int mod = 998244353; void solve() { int n, k; cin >> n >> k; int mn = 1e9; vector<pair<int, int>> vec(n); vector<pair<int, int>> ans; for(int i = 0; i < n; i++) { cin >> vec[i].first; vec[i].second = i; ans.push_back({vec[i].first, 0}); mn = min(mn, vec[i].first); } while(mn < 30) { vector<pair<int, int>> add; vector<pair<int, int>> v2; int c = 0; int del = 0; for(int i = 0; i < vec.size(); i++) { if(vec[i].first == mn) { if(c == 0) c++; else { c = 0; v2.push_back({vec[i].first + 1, vec[i].second + del}); } } else { if(c) { c = 0; del++; v2.push_back({vec[i - 1].first + 1, vec[i - 1].second + del}); add.push_back({vec[i - 1].first, vec[i - 1].second + del}); } v2.push_back({vec[i].first, vec[i].second + del}); } } if(c) { c = 0; del++; v2.push_back({vec.back().first + 1, vec.back().second + del}); add.push_back({vec.back().first, vec.back().second + del}); } vector<pair<int, int>> vans; reverse(add.begin(), add.end()); for(int i = 0; !add.empty() || i < ans.size(); i++) { if(!add.empty() && i == add.back().second) { vans.push_back({add.back().first, 1}); add.pop_back(); } if(i < ans.size()) vans.push_back(ans[i]); } ans = vans; mn++; vec = v2; // cout << "\n\n"; // for(auto i : vec) // cout << i.first << ' '; // cout << '\n'; } // cout << ans.size() << '\n'; // return; int len = n + k - ans.size(); map<int, vector<int>> mp; for(int i = 0; i < ans.size(); i++) { if(ans[i].second) mp[i].push_back(ans[i].first); } while(len) { for(auto &i : mp) { vector<int> v2; for(auto j : i.second) { if(j == 0 || len == 0) v2.push_back(j); else { len--; v2.push_back(j - 1); v2.push_back(j - 1); } } i.second = v2; } } for(int i = 0; i < ans.size(); i++) { if(ans[i].second) cout << ans[i].first << ' '; else { for(auto j : mp[i]) cout << j << ' '; } } cout << "\n"; } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T = 1; for (; T--; solve()); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...