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;
#define ll long long
std::vector<int> construct_permutation(long long k)
{
int sz = 10000;
vector<int> best;
for(ll l = 1 ;l < 10000 ;l++)
{
ll x = k + l - 1;
if(__builtin_popcountll(x) <= l)
{
int n = 0;
multiset<int> bits;
for(ll i = 0 ; i < 61 ; i++)
{
if((1ll<<i) & x)
{
bits.insert(i);
}
}
bool ok = 1;
while ((int)bits.size() < l)
{
auto it = upper_bound(bits.begin() , bits.end() ,0);
if(it == bits.end())
{
ok = 0;
break;
}
int val = *it;
bits.erase(it);
bits.insert(val - 1);
bits.insert(val - 1);
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |