#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
std::vector<int> construct_permutation(long long k)
{
int sz = 10000;
vector<int> best;
for(ll l = 1 ;l < 61 ;l++)
{
ll x = k + l - 1;
if(__builtin_popcountll(x) <= l)
{
int n = 0;
vector<int> bits;
for(ll i = 0 ; i < 61 ; i++)
{
if((1ll<<i) & x)
{
bits.push_back(i);
}
}
bool ok = 1;
while ((int)bits.size() < l)
{
bool acc = 0;
for(int i = 0 ; (int)bits.size()< l && i < (int)bits.size() ; i++)
{
int bit = bits[i];
if(bit >= 1)
{
acc = 1;
bits[i] = --bit;
bits.push_back(bits[i]);
}
}
if(!acc)
{
ok = 0;
break;
}
}
if(!ok)
continue;
for(auto bit : bits)
n+=bit;
n--;
vector<int> perm;
for(auto i : bits)
{
for(int j = n - i + 1 ; j <= n ; j++)
{
perm.push_back(j);
}
n-=i;
}
if((int)perm.size() < sz)
{
sz = (int)perm.size();
best = perm;
}
}
}
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Partially correct |
5 ms |
348 KB |
Partially correct |
4 |
Partially correct |
5 ms |
484 KB |
Partially correct |
5 |
Partially correct |
8 ms |
600 KB |
Partially correct |
6 |
Partially correct |
8 ms |
732 KB |
Partially correct |
7 |
Partially correct |
10 ms |
856 KB |
Partially correct |
8 |
Partially correct |
15 ms |
1116 KB |
Partially correct |
9 |
Partially correct |
9 ms |
348 KB |
Partially correct |
10 |
Partially correct |
12 ms |
1116 KB |
Partially correct |
11 |
Partially correct |
12 ms |
860 KB |
Partially correct |
12 |
Partially correct |
11 ms |
1016 KB |
Partially correct |
13 |
Partially correct |
12 ms |
860 KB |
Partially correct |