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>
using namespace std;
int pivot;
vector<int> rs;
void backtrack(long long k) {
if (!k)
return;
int pw2 = 1, cnt = 0;
while (pw2 * 2 - 1 <= k) {
pw2 *= 2;
cnt++;
}
for (int i = pivot - cnt + 1; i <= pivot; i++)
rs.push_back(i);
pivot -= cnt;
backtrack(k - pw2 + 1);
}
std::vector<int> construct_permutation(long long k) {
pivot = 1e9;
rs.clear();
backtrack(k - 1);
int minVal = *min_element(rs.begin(), rs.end());
// cout << minVal << '\n';
// for (int &x: rs)
// cout << x << ' ';
// cout << '\n';
for (int &x: rs)
x -= minVal;
return rs;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |