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"
using namespace std;
#include <iostream>
#include <random>
using ll = long long;
mt19937_64 rng(0);
std::vector<int> construct_permutation(long long k)
{
vector<int>ret = { -1};
vector<ll>dp = {1};
k--;
while (k != 0)
{
int sz = (int)ret.size();
for (int i = sz - 1; i >= 0; i--)
{
ll sum = 0;
for (int j = 0; j < (int)ret.size(); j++)
if (ret[j] < i)
sum += dp[j];
if (rng() % 5 == 0 && i != 0 && sum != k)
continue;
if (sum <= k)
{
k -= sum;
dp.push_back(sum);
for (int &j : ret)
if (j >= i)
j++;
ret.push_back(i);
break;
}
}
}
ret.erase(ret.begin());
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |