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;
mt19937 rng(time(NULL));
long long dp[120], a[120];
std::vector<int> construct_permutation(long long k) {
long long cur = 1;
int n = 0;
while(cur<k) {
vector<pair<int, long long> > b;
for(int i = 1; i <= n; ++i) {
b.push_back({a[i], dp[i]});
}
sort(b.begin(), b.end());
long long add = 1, need = k-cur;
int nxt = 0;
for(auto [x, y] : b) {
if(add+y<=need) {
nxt = x+1;
add += y;
}
}
for(int i = 0; i <= n; ++i) {
if(a[i] >= nxt) {
a[i]++;
}
}
a[++n] = nxt;
dp[n] = add;
cur += add;
}
vector<int> ans;
for(int i = 1; i <= n; ++i) {
ans.push_back(a[i]);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |