제출 #594371

#제출 시각아이디문제언어결과실행 시간메모리
594371mohammad_kilani순열 (APIO22_perm)C++17
91.33 / 100
3 ms340 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 -= (1LL << mx) - 1; bool add = false; a = 0; mx = 0; while((1LL << (mx + 1)) <= k) mx++; for(int i = 0 ;i <= mx;i++){ if(((k >> i) & 1) == 1) a++; } if(a > mx + 1 - a){ k--; add = true; } 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...