#include<bits/stdc++.h>
#include "perm.h"
using namespace std;
std::vector<int> construct_permutation(long long k)
{
int l = 0;
for (int i = 62; i>= 0; i--)
{
if (k&(1LL<<i)) l =max(l,i);
}
vector<int> sol(l);
iota(sol.begin(), sol.end(), 0);
int added = 0;
int d = l;
for (int i = l-1; i >= 0; i--)
{
if (k&(1LL<<i))
{
if (i%2 && k&(1LL<<(i-1)) && added>=3)
{
i--;
int h = 0;
for (int j = sol.size()-1; j >= 0; j--)
{
if (sol[j]>=l)
{
sol[j]++;
h++;
}
if (h==3) break;
}
sol.push_back(0);
for (int j = sol.size()-1; j > i; j--)
{
sol[j] = sol[j-1];
}
sol[i] = d++ - 3;
}
else
{
sol.push_back(0);
for (int j = sol.size()-1; j >i; j--)
{
sol[j] = sol[j-1];
}
sol[i] = d++;
added++;
}
}
}
return sol;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |