# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
896855 | Litusiano | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
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<bits/stdc++.h>
#include "perm.h"
using namespace std;
const int CT = 1000;
long long getdp(vector<int>& v) {
vector<long long> dp(v.size() + 1, 0);
dp[0] = 1;
for (int x : v)
{
for (int i = 0; i <= x; i++)
{
dp[x+1] += dp[i];
dp[x+1] = min(dp[x+1],MX+1);
}
}
long long result = 0;
for (int i = 0; i <= (int)v.size(); i++){
result += dp[i];
result = min(result,MX+1);
}
return result;
}
vector<int> construct_permutation(long long k)
{
const int CT = 1000;
if(k <= 90){
vector<int> v;
for(int i = 0; i<k; i++){
v.push_back(k);
}
return v;
}
vector<int> v;
for(int a = 1; i<=90; i++){
v.push_back(a);
if(a > 8){
for(int _ = 0; _ < CT; _++){
v = shuffle(v);
if(getdp(v) == k){
return v;
}
}
}
else{
sort(v.begin(),v.end());
do{
if(getdp(v) == k) return v;
}while(next_permutation(v.begin(),v.end()));
}
}
}