#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k) {
int b = 63 - __builtin_clzll(k);
k -= 1LL << b;
vector<int> key(b);
iota(key.begin(), key.end(), 0);
int cnt = 0;
while (k > 0) {
b = 63 - __builtin_clzll(k);
if (cnt >= 1 && b > 0 && ((k >> (b - 1)) & 1)) {
b--;
for (int &v : key) {
if (v >= b) v++;
}
key.insert(key.end() - 2, b);
k -= 3LL << b;
} else {
for (int &v : key) {
if (v >= b) v++;
}
key.push_back(b);
k -= 1LL << b;
cnt++;
}
}
return key;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
2 ms |
348 KB |
Output is correct |