Submission #983191

#TimeUsernameProblemLanguageResultExecution timeMemory
983191KenjikrabPermutation (APIO22_perm)C++17
100 / 100
2 ms348 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; deque<int> find_p(long long k,int shift) { deque<int> ret; if(k==2) { ret.push_back(shift); return ret; } if(k==3) { ret.push_back(shift+1); ret.push_back(shift); return ret; } if(k==5) { ret.push_back(shift+1); ret.push_back(shift+2); ret.push_back(shift); return ret; } if(k==17) { ret.push_back(shift+4); ret.push_back(shift); ret.push_back(shift+1); ret.push_back(shift+2); ret.push_back(shift+3); return ret; } if(k%2==0) { ret=find_p(k/2,shift); int sz=ret.size(); ret.push_back(shift+sz); return ret; } else if(k%3==0) { ret=find_p(k/3,shift); int sz=ret.size(); ret.push_back(shift+sz+1); ret.push_back(shift+sz); return ret; } else if(k%5==0) { ret=find_p(k/5,shift); int sz=ret.size(); ret.push_back(shift+sz+2); ret.push_back(shift+sz); ret.push_back(shift+sz+1); return ret; } else if(k%17==0) { ret=find_p(k/17,shift); int sz=ret.size(); ret.push_back(shift+sz+4); ret.push_back(shift+sz); ret.push_back(shift+sz+1); ret.push_back(shift+sz+2); ret.push_back(shift+sz+3); return ret; } else { ret=find_p(k-1,shift); int sz=ret.size(); ret.push_front(shift+sz); return ret; } } vector<int> construct_permutation(long long k) { /* vector<int> a; vector<int> ret; while(k>0) { if(k%2==1)a.push_back(1); else a.push_back(0); k/=2; } int n=a.size(); int idx=0; for(idx=0;idx<n-1;idx++)ret.push_back(idx); for(int i=n-2;i>=0;i--) { if(a[i]==0)continue; ret.insert(ret.begin()+i,idx++); } */ vector<int> ret; deque<int> temp=find_p(k,0); while(!temp.empty()){ret.push_back(temp.front());temp.pop_front();} return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...