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 <iostream>
#include <vector>
using namespace std;
vector<int> construct_permutation(long long k) {
long long int n = k, cnt = 1, sz, a[110];
for (int i = 1; i <= 100; i++) a[i] = 0;
while ((1LL<<cnt)-1 <= n) cnt++;
cnt--;
sz = cnt;
n -= (1LL<<cnt)-1;
for (int i = 1; i <= cnt; i++) a[i] = i-1;
while (cnt >= 0) {
if ((1LL<<cnt) <= n) {
n -= (1LL<<cnt);
for (int i = sz; i >= 1; i--) a[i+1] = a[i];
sz++;
if (cnt) a[1] = a[sz-cnt+1];
else a[1] = a[sz]+1;
for (int i = sz; i >= sz-cnt+1; i--) a[i]++;
}
cnt--;
}
vector<int> ans;
for (int i = 1; i <= sz; i++) ans.push_back(a[i]);
return ans;
}
/*int main() {
long long int k;
vector<int> b;
cin >> k;
b = construct_permutation(k);
for (int i = 0; i < b.size(); i++) cout << b[i] << " ";
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |