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 "perm.h"
#include <algorithm>
std::vector<int> construct_permutation(long long K) {
if (K == 1) return {};
if (K == 2) return {0};
if (K == 3) return {1, 0};
auto ret = construct_permutation(K / 4);
const int n = (int)ret.size();
ret.push_back(n);
if (K % 4 <= 1) {
ret.push_back(n + 1);
if (K % 4 == 1) ret.push_back(-1);
} else if (K % 4 == 2) {
ret.push_back(-1);
ret.push_back(n + 1);
} else {
int zero = -1, one = n;
for (int i = 0; i < n; ++i) {
if (ret[i] == 0) zero = i;
if (ret[i] == 1) one = i;
}
if (one < zero) {
ret.push_back(n + 1);
for (auto& x : ret) {
if (x >= 2) x += 1;
}
ret.push_back(2);
} else {
ret.push_back(-1);
ret.push_back(n + 1);
ret.push_back(-2);
}
}
const int min = *std::min_element(std::begin(ret), std::end(ret));
for (auto& x : ret) x -= min;
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |