Submission #958209

#TimeUsernameProblemLanguageResultExecution timeMemory
958209pragmatistPermutation (APIO22_perm)C++17
91.33 / 100
11 ms456 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...