# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011720 | dimashhh | Permutation (APIO22_perm) | C++17 | 959 ms | 720 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 "perm.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[150];
ll K;
ll calc(vector<int> x){
ll S = 1;
for(int i = 0;i < (int)x.size();i++){
dp[i] = 1;
for(int j = i - 1;j >= 0;j--){
if(x[j] < x[i]){
dp[i] += dp[j];
if(dp[i] > K) return K + 1;
}
}
S += dp[i];
if(S > K) return K + 1;
}
return S;
}
vector<int> ins(vector<int> &x,int a){
vector<int> ret = x;
for(int i = 0;i < (int)ret.size();i++){
if(ret[i] >= a){
ret[i]++;
}
}
ret.push_back(a);
return ret;
}
vector<int> construct_permutation(long long k)
{
K = k;
ll G = 1;
vector<int> a;
while(G != k){
ll mx = -1;
int pos;
for(int i = 0;i <= (int)a.size();i++){
ll val = calc(ins(a,i));
if(val <= k){
if(val > mx){
mx = val;
pos = i;
}
}
}
G = mx;
a = ins(a,pos);
}
return a;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |