# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
605435 | AugustinasJucas | Permutation (APIO22_perm) | C++17 | 1078 ms | 1348 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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k) {
vector<int> RET(3000, 0);
long long K = k;
for(int H = 0; H < k-1; H++){
k = K - H;
vector<int> init;
int ind = 0;
long long liko = 0;
for(int i = 0; i < 64; i++) {
long long bus = (1ll << i);
if(bus > k) {
// desim i-1 tu.
for(int j = 0; j < i-1; j++) init.push_back(ind++);
liko = k - (1ll << (i-1));
break;
}
}
// cout << "liko = " << liko << ", popcnt = " << __builtin_popcount(liko) << endl;
vector<int> ret;
ind += __builtin_popcountll(liko) - 1 + H;
for(int i = 0; i < H; i++) {
ret.push_back(ind--);
}
for(int i = 0; i < init.size(); i++) {
if((1ll << i) & liko) {
ret.push_back(ind);
ind--;
}
ret.push_back(init[i]);
}
if(ret.size() < RET.size()) {
RET = ret;
}
// cout << "ret = "; for(auto x : ret) cout << x << " ";
//cout << endl;
}
return RET;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |