Submission #1244542

#TimeUsernameProblemLanguageResultExecution timeMemory
1244542fauntleroyZalmoxis (BOI18_zalmoxis)C++20
0 / 100
225 ms327680 KiB
#include <iostream> #include <cstdio> #include <vector> #include <array> #include <string> #include <algorithm> #include <numeric> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <cmath> #include <climits> #include <iomanip> #include <limits> #include <tuple> #include <stack> #include <bitset> #include <cstring> #include <sstream> #include <functional> #include <random> #define int long long using namespace std; int pa, pd; void build(int x, int k, vector<int>& ans, vector<int>& a, vector<int>& dod) { int n = a.size(); if (pa < n && a[pa] == x) { ans.push_back(x); ++pa; } else if (pd < k && dod[pd] == x) { ans.push_back(x); ++pd; } else { build(x - 1, k, ans, a, dod); build(x - 1, k, ans, a, dod); } } void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (auto& e : a) cin >> e; vector<int> v, pv; for (int i = 0; i < n; ++i) { v.push_back(a[i]); pv.push_back(i); while (v.size() > 1 && v[v.size() - 1] == v[v.size() - 2]) { v.pop_back(); pv.pop_back(); ++v.back(); } } vector<int> dod; int s = *min_element(v.begin(), v.end()) - k + 1; dod.push_back(s); for (int i = 0; i < k - 1; ++i) dod.push_back(s++); vector<int> ans; build(30, k, ans, a, dod); for (auto& e : ans) cout << e << ' '; cout << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...