Submission #602996

#TimeUsernameProblemLanguageResultExecution timeMemory
602996tutisPermutation (APIO22_perm)C++17
91.33 / 100
2 ms340 KiB
#include "perm.h" using namespace std; #include <iostream> #include <random> #include <functional> #include <map> using ll = long long; std::vector<int> construct_permutation(long long k) { if (k % 2 == 0) { vector<int>a = construct_permutation(k / 2); a.push_back((int)a.size()); return a; } if (k % 2 == 1 && k > 1000) { vector<int>a = construct_permutation(k - 1); a.insert(a.begin(), (int)a.size()); return a; } 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 (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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...