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 <bits/stdc++.h>
std::vector<int> construct_permutation(long long k) {
if (k < 4) {
if (k == 1) return {};
if (k == 2) return {0};
return {1, 0};
}
auto v = construct_permutation(k / 4);
int r = k % 4;
if (r == 0) {
v.push_back(v.size());
v.push_back(v.size());
return v;
}
if (r == 1) {
v.push_back(v.size());
v.push_back(v.size());
v.insert(v.begin(), v.size());
return v;
}
if (r == 2) {
// adding two into our thing
v.push_back(v.size());
v.push_back(v.size());
v.insert(v.begin() + 1, v.size());
return v;
}
int p0 = std::find(v.begin(), v.end(), 0) - v.begin();
int p1 = std::find(v.begin(), v.end(), 1) - v.begin();
if (p1 < p0) {
v.push_back(v.size());
v.push_back(v.size());
for (int& i : v) {
if (i >= 2) {
i++;
}
}
v.push_back(2);
return v;
}
// p1 > p0
v.push_back(v.size());
v.push_back(v.size());
for (int& i : v) {
if (i >= 1) i++;
}
v.push_back(1);
for (int& i : v) {
i++;
}
v.push_back(0);
return v;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |