Submission #1035336

#TimeUsernameProblemLanguageResultExecution timeMemory
1035336amine_arouaPermutation (APIO22_perm)C++17
71.22 / 100
9 ms1420 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; #define ll long long vector<int> bits; void add(ll k) { if(k == 0) { return; } for(ll i = 59 ; i >= 1 ; i--) { if(k - ((1ll<<i) - 1) >= 0) { bits.push_back(i); k-=((1ll<<i) - 1); add(k); break; } } } std::vector<int> construct_permutation(long long k) { k--; int n = 0; bits.clear(); for(ll i = 0 ; i < 60 ; i++) { if((1ll<<i) & k) { bits.push_back(i); n+=i + 1; } } n--; vector<int> perm; for(auto i : bits) { for(int j = n - i + 1 ; j <= n ; j++) { perm.push_back(j); } n-=i; } while(n >= 0) { perm.push_back(n); n--; } vector<int> best = perm; perm.clear(); bits.clear(); n = 0; add(k); for(auto bit : bits) n+=bit; n--; for(auto i : bits) { for(int j = n - i + 1 ; j <= n ; j++) { perm.push_back(j); } n-=i; } if((int)perm.size()< (int)best.size()) return perm; else return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...