Submission #838774

#TimeUsernameProblemLanguageResultExecution timeMemory
838774arbuzickPermutation (APIO22_perm)C++17
91.33 / 100
2 ms380 KiB
#include <bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k) { k--; int len = 0; for (int i = 60; i > 0; --i) { if ((1LL << i) - 1 <= k) { k -= ((1LL << i) - 1); len = i; break; } } vector<int> count(len + 1); for (int i = 60; i >= 0; --i) { long long vl = (1LL << i); while (k >= vl) { count[i]++; k -= vl; } } vector<int> ans; int p = 0; for (int i = len; i > 0; --i) { p += count[i]; ans.push_back(p); p++; } p = 0; reverse(ans.begin(), ans.end()); for (int i = len; i >= 0; --i) { for (int j = 0; j < count[i]; ++j) { ans.push_back(p); p++; } p++; } reverse(ans.begin(), ans.end()); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...