제출 #912480

#제출 시각아이디문제언어결과실행 시간메모리
912480stegatxins0순열 (APIO22_perm)C++17
100 / 100
2 ms600 KiB
#include <bits/stdc++.h> #include "perm.h" using namespace std; using ll = long long; std::vector<int> construct_permutation(long long k) { int n = __lg(k); int ma1,ma2,cur=2; vector<int> ans(n); iota(ans.begin(),ans.end(),0); for(int i=n-1; i>=0;i--){ if((k>>i)&1){ if(cur){ if(cur == 2){ ma2 = i+1; ans.insert(ans.begin()+i, n); } if(cur == 1){ ma1 = i; ans.insert(ans.begin()+i, n+1); } cur--; } else if(i-1>=0 && (k>>(i-1))&1 ){ ans[ma1]++; ans[ma2]++; ans.insert(ans.begin()+i-1, ans[ma2]-1); ma1++; ma2++; i--; }else{ ans.insert(ans.begin()+i, ans[ma1]+1); ma2 = ma1+1; ma1 = i; } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...