Submission #603038

#TimeUsernameProblemLanguageResultExecution timeMemory
603038tutisPermutation (APIO22_perm)C++17
10 / 100
1 ms300 KiB
#include "perm.h" using namespace std; #include <iostream> #include <random> #include <functional> #include <cassert> #include <map> using ll = long long; std::vector<int> construct_permutation(long long k, bool v) { if (k > 100) { if (k % 2 == 0) { vector<int>a = construct_permutation(k / 2, v); a.push_back((int)a.size()); return a; } if (k % 4 == 3 && k > 1000) { vector<int>a = construct_permutation(k - 3, true); for (int &i : a) if (i >= 2) i++; a.push_back(2); return a; } if (k % 2 == 1 && k > 1000) { vector<int>a = construct_permutation(k - 1, v); for (int &i : a) if (i >= 0) i++; a.push_back(0); return a; } } vector<int>ret = { -1}; vector<ll>dp = {1}; if (v) { assert(k >= 3); vector<int>ret = { -1, 1, 0}; vector<ll>dp = {1, 1, 1}; } for (int i : dp) k -= i; 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; } vector<int> construct_permutation(long long k) { return construct_permutation(k, false); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...