Submission #742338

#TimeUsernameProblemLanguageResultExecution timeMemory
742338khshgPermutation (APIO22_perm)C++17
93.67 / 100
3 ms340 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; #define mp make_pair #define ff first #define ss second template<class T> using V = vector<T>; #define arr array using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<ld>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; using vpd = V<pd>; #define sz(x) (int)((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define rep(a) F0R(_, a) #define trav(a, x) for(auto& a : x) template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); } template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); } vi construct_permutation(ll k) { V<char> bits; F0R(i, 62) { bits.eb(k % 3LL); k /= 3LL; } deque<char> ans; int mn = 0, mx = 1; while(!bits.bk) bits.pop_back(); if(bits.bk == 2) { ans.eb(0); mn = -1; mx = 1; } bits.pop_back(); reverse(all(bits)); F0R(i, sz(bits)) { char cur = bits[i]; if(!cur) { ans.eb(mx + 1); ans.eb(mx); mx += 2; } else if(cur == 1) { ans.eb(mx + 1); ans.eb(mx); mx += 2; ans.eb(mn); --mn; } else { ans.emplace_front(mx + 1); ans.eb(mx + 2); ans.eb(mx); mx += 3; } } vi rans(all(ans)); mn = 0x3f3f3f3f; trav(u, rans) ckmin(mn, u); trav(u, rans) u -= mn; return rans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...