Submission #623820

#TimeUsernameProblemLanguageResultExecution timeMemory
623820iomoon191Permutation (APIO22_perm)C++17
100 / 100
4 ms340 KiB
#include <perm.h> using ll = long long; //#define int ll using namespace std; #define sz(x) (int)(x).size() #define foru(i, l, r) for(int i = l; i <= r; i++) #define ford(i, l, r) for(int i = l; i >= r; i--) #define fi first #define se second #define mod 998244353 #define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n" using vi = vector<int>; using pi = pair<int, int>; const ll N = 200005; const ll inf = 1e18; vi construct_permutation(ll k){ if(k == 1) return {}; if(k == 2) return {0}; if(k == 3) return {1, 0}; vi d = construct_permutation(k >> 2); int s = sz(d); if(k % 4 == 0){ d.push_back(s); d.push_back(s + 1); return d; } if(k % 4 == 1){ d.push_back(s); d.push_back(s + 1); d.push_back(-1); for(auto &i : d) i++; return d; } if(k % 4 == 2){ d.push_back(s); d.push_back(-1); d.push_back(s + 1); for(auto &i : d) i++; return d; } vi _d = d; d.push_back(s); d.push_back(s + 1); for(auto &i : d) if(i > 1) i++; d.push_back(2); vector<ll> f(sz(d)); ll sum = 1; foru(i, 0, sz(d) - 1){ f[i] = 1; foru(j, 0, i - 1){ if(d[j] < d[i]) f[i] += f[j]; f[i] = min(f[i], inf); } sum += f[i]; sum = min(sum, inf); } if(sum == k) return d; for(auto &i : _d) i += 2; _d.push_back(s + 2); _d.push_back(1); _d.push_back(s + 3); _d.push_back(0); return _d; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...