# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68585 | aome | Zalmoxis (BOI18_zalmoxis) | C++17 | 1098 ms | 46508 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;
vector<int> vres, vcur, vadd;
void add() {
int tmp = vcur.back();
vadd.push_back(vres.size());
vres.push_back(tmp);
++tmp;
vcur.pop_back();
while (vcur.size() && vcur.back() == tmp) {
vcur.pop_back(), tmp++;
}
vcur.push_back(tmp);
}
void cal(int val, int need) {
if (need == 1) {
printf("%d ", val); return;
}
int tmp = min(need - 1, (1 << (val - 2)));
cal(val - 1, tmp), cal(val - 1, need - tmp);
}
int main() {
int n, m, x;
scanf("%d %d %d", &n, &m, &x);
vres.push_back(x), vcur.push_back(x);
for (int i = 1; i < n; ++i) {
scanf("%d", &x);
if (vcur.back() > x) {
vres.push_back(x), vcur.push_back(x);
}
else {
while (vcur.back() < x) add();
if (vcur.back() > x) {
vres.push_back(x), vcur.push_back(x);
}
else {
vres.push_back(x);
++x;
vcur.pop_back();
while (vcur.size() && vcur.back() == x) {
vcur.pop_back(), x++;
}
vcur.push_back(x);
}
}
}
while (vcur.back() != 30) add();
int ptr = 0;
for (int i = 0; i < vres.size(); ++i) {
if (ptr < vadd.size() && vadd[ptr] == i) {
++ptr;
int tmp = min(m - ((int)vadd.size() - ptr), 1 << (vres[i] - 1));
m -= tmp;
cal(vres[i], tmp);
}
else printf("%d ", vres[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |