#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k)
{
vector<int> binary;
while (k) {
binary.push_back(k & 1);
k >>= 1;
}
reverse(binary.begin(), binary.end());
deque<int> dq;
int cnt = 0, sz = (int)binary.size(), cntt = 0;
for (int i = 1; i < sz; ++i) {
dq.emplace_back(cnt++);
if (binary[i]) {
if (i + 1 < sz and binary[i + 1] and cntt > 1) {
int val = dq.front(); dq.pop_front();
dq.emplace_back(cnt++);
dq.emplace_front(cnt++);
dq.emplace_front(val);
}
else dq.emplace_front(cnt++), cntt++;
}
}
return {dq.begin(), dq.end()};
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |