# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
767157 | Ahmed57 | Permutation (APIO22_perm) | C++17 | 0 ms | 0 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;
int[] construct_permutation(long long k){
k--;
vector<long long> v;
for(long long i = 0;i<60;i++){
if((1LL<<i)<=k){
k-=(1LL<<i);
v.push_back(i);
}
}
for(long long i = 59;i>=0;i--){
while((1LL<<i)<=k){
long long xd = i;
for(int j = v.size()-1;j>=xd;j--){
v[j]++;
}
v.push_back(i);
n-=(1LL<<i);
}
}
int arr[v.size()];
for(int i = 0;i<v.size();i++)arr[i] = v[i];
return arr;
}