Submission #720637

#TimeUsernameProblemLanguageResultExecution timeMemory
720637stevancvPermutation (APIO22_perm)C++17
10 / 100
2 ms340 KiB
#include <bits/stdc++.h> #include "perm.h" #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; const int inf = 1e9; ll C(ll a, ll b) { return (a + b - 1) / b; } vector<int> construct_permutation(ll k) { if (k <= 115) { vector<int> ret(k - 1); for (int i = 0; i < k - 1; i++) ret[i] = k - 2 - i; return ret; } int n = 115; vector<int> ret(n); for (int i = 0; i < n; i++) ret[i] = n - 1 - i; k -= n + 1; ll prv = n; for (int i = n - 1; i >= 0 && k; i--) { ll e = n - i; ll j = i; smin(j, C(k, 1ll << (e - 1))); if (k % (1ll << e) == 0 && j % 2 != 0) j -= 1; if (k % (1ll << e) != 0 && j % 2 == 0) j -= 1; if ((j + prv) % 2 == 0) smin(j, prv - 2); else smin(j, prv - 1); prv = j; for (int p = n - 1; p > n - 1 - j; p--) swap(ret[p], ret[p - 1]); k -= (1ll << (e - 1)) * j; } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...