# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861859 | maks007 | Zalmoxis (BOI18_zalmoxis) | C++14 | 122 ms | 51004 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define int long long
int k;
vector <pair <int,int>> ans;
vector <int> a;
void decomp(int v) {
stack <int> q;
vector <int> ans2;
q.push(v);
while(q.size() + ans2.size() != k + 1) {
int v = q.top();
q.pop();
if(v == 0) {
ans2.push_back(v);
continue;
}
q.push(v-1);
q.push(v-1);
}
while(q.size()) {
int v =q.top();
q.pop();
ans2.push_back(v);
}
for(auto i : ans2) cout << i << " ";
}
void f(int v) {
if(a.size() == 0) {
ans.push_back({v, 1});
return;
}
if(v == a.back()) {
ans.push_back({v,0});
a.pop_back();
return;
}
if(a.back() > v) {
ans.push_back({v,1});
return;
}
f(v-1);
f(v-1);
}
signed main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, cnt = 0;
cin >> n >> k;
for(int i = 0; i < n; i ++) {
int x;
cin >> x;
a.push_back(x);
}
reverse(a.begin(), a.end());
f(30);
// assert()
// for(auto i : ans) cout << i.first << " ";
for(auto i : ans) k -= i.second;
if(k < 0) {
while(1){}
}
for(auto i : ans) {
if(i.second == 0) cout << i.first << " ";
else if(k){
decomp(i.first);
}else cout << i.first << " ";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |