# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982880 | vjudge1 | Permutation (APIO22_perm) | C++17 | 2 ms | 600 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> construct_permutation(long long k) {
k--;
vector<int> arr;
for (long long i = 1, j = 0; k; j++, i *= 2) {
if (k % 2 == 1) {
arr.push_back(1);
k /= 2;
} else {
arr.push_back(2);
k -= 2;
k /= 2;
}
}
//for(auto it: arr) cout<<it<<' ';
int x = 0;
for (int i = 0; i < arr.size(); i++, x++)
if (arr[i] == 2) x++;
vector<int> ans(x);
for (int j = 0, k = x - 1, l = 0, p = 0; j < x; j++, p++) {
if (arr[p] == 1) {
ans[j] = l;
l++;
} else {
ans[j] = k;
ans[j + 1] = l;
k--;
l++;
j++;
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |