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;
long long k, sum = 1;
vector<long long>f;
vector<int> ans;
long long get(long long cur, long long x){
if (x >= 60)
return 1LL << 60;
if (k / cur < (1 << x))
return cur * (1 << x);
return 1LL << 60;
}
std::vector<int> construct_permutation(long long K){
ans.clear();
f.clear();
k = K;
f.push_back(1);
ans.push_back(0);
sum = 1;
for (int i = 1; sum < k; i++){
if (sum * 2 <= k){
ans.push_back(i);
f.push_back(sum);
sum <<= 1;
continue;
}
for (long long j = (int)f.size() - 1, d = sum; j > 0; j--){
d -= f[j];
if (sum + d <= k){
sum += d;
ans.insert(ans.begin() + j, i);
f.insert(f.begin() + j, d);
break;
}
}
}
ans.erase(ans.begin());
for (int i = 0; i < (int)ans.size(); i++)
ans[i]--;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |