제출 #638568

#제출 시각아이디문제언어결과실행 시간메모리
638568bachhoangxuan순열 (APIO22_perm)C++17
100 / 100
2 ms340 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k){ if(k==1) return {}; else if(k==2) return {0}; else if(k==3) return {1,0}; vector<int> res=construct_permutation(k>>2); int s=(int)res.size(); if(k%4==0){res.push_back(s);res.push_back(s+1);} else if(k%4==1){res.push_back(s);res.push_back(s+1);res.push_back(-1);for(int &x:res) x++;} else if(k%4==2){res.push_back(s);res.push_back(-1);res.push_back(s+1);for(int &x:res) x++;} if(k%4!=3) return res; if((k>>2)<=2 || (k>>2)%4==0){ res.push_back(s);res.push_back(-1);res.push_back(s+1);res.push_back(-2); for(int &x:res) x+=2; } else{ res.push_back(s);res.push_back(s+1); for(int &x:res){if(x>=2) x++;} res.push_back(2); } return res; } /* signed main(){ int n;cin >> n; vector<int> res=construct_permutation(n); for(int v:res) cout << v << ' '; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...