Submission #888428

#TimeUsernameProblemLanguageResultExecution timeMemory
888428green_gold_dogPermutation (APIO22_perm)C++17
100 / 100
1 ms388 KiB
#include<bits/stdc++.h> #include "perm.h" typedef long long ll; using namespace std; void add1(vector<int>& ans) { for (auto& i : ans) { i++; } ans.push_back(0); } void add3(vector<int>& ans) { ans.insert(ans.begin() + 2, ans.size()); } void mul2(vector<int>& ans) { ans.push_back(ans.size()); } std::vector<int> construct_permutation(long long k) { if (k <= 90) { vector<int> all; for (ll i = 0; i < k - 1; i++) { all.push_back(i); } reverse(all.begin(), all.end()); return all; } vector<ll> all; while (k) { all.push_back(k & 1); k /= 2; } vector<int> ans; ans.push_back(1); ans.push_back(0); all.pop_back(); ll lst = all.back(); all.pop_back(); if (!lst) { lst = all.back(); all.pop_back(); add1(ans); if (lst) { add1(ans); } } while (!all.empty()) { lst = all.back(); all.pop_back(); mul2(ans); if (lst) { if (!all.empty() && all.back()) { all.pop_back(); mul2(ans); add3(ans); } else { add1(ans); } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...