# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
596663 | slime | Permutation (APIO22_perm) | C++17 | 3 ms | 340 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;
int fastlog(long long x) {
return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
std::vector<int> construct_permutation(long long k)
{
// x3: 2 0 1 "4 3"
// x6: 2 0 1 "4 3 5"
// +1: "3" 2 0 1
// +2: "4 3" 2 0 1
vector<int> cur = {};
vector<int> bit;
bool begin = 0;
long long pow3[38];
pow3[0] = 1;
for(int i=1; i<38; i++) pow3[i] = pow3[i-1] * 3;
long long kpr = k;
for(int i = 37; i >= 0; i--) {
if(kpr >= pow3[i]) {
bit.push_back(kpr / pow3[i]);
begin = 1;
kpr %= pow3[i];
}
else if(begin) bit.push_back(0);
}
if(bit[0] == 2) {
cur.push_back(0);
}
for(int i = 1; i < bit.size(); i++) {
int n = cur.size();
cur.push_back(n + 1);
cur.push_back(n);
for(int j = 0; j < bit[i]; j++) {
int n = cur.size();
vector<int> nw;
nw.push_back(n);
for(int x: cur) nw.push_back(x);
cur = nw;
}
}
return cur;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |