Submission #594364

#TimeUsernameProblemLanguageResultExecution timeMemory
594364mohammad_kilaniPermutation (APIO22_perm)C++17
10 / 100
1 ms296 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; std::vector<int> construct_permutation(long long k){ k--; vector< int > ret; int mx = 0; while((1LL << (mx + 1)) <= k) mx++; int a = 0; for(int i = 0 ;i <= mx;i++){ if(((k >> i) & 1) == 1) a++; } if(a == mx + 1){ for(int i = 0 ;i <= mx;i++) ret.push_back(i); return ret; } for(int i = 0 ;i < mx;i++) ret.push_back(i); k -= (1 << mx) - 1; bool add = false; if(a - 1 > mx - a){ add = true; k--; } for(int i = 59 ;i >= 0;i--){ if(((k >> i) & 1) == 1){ ret.insert(ret.begin() + i , (int)ret.size()); } } if(add) ret.insert(ret.begin(), (int)ret.size()); return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...