Submission #738981

#TimeUsernameProblemLanguageResultExecution timeMemory
738981Prieved1Permutation (APIO22_perm)C++17
91.33 / 100
2 ms340 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; std::vector<int> construct_permutation(long long k) { vector<int> v; { long long tmp=2; while(tmp<=k) { v.push_back(v.size()); tmp*=2; } k-=tmp/2; } cerr << v.size() << endl; vector<int> add; vector<long long> b4; while(k>0) { b4.push_back(k%4); k/=4; } for(int i =0;i<(int)b4.size();i++) { if(b4[i]==0)continue; else if(b4[i]==1) { add.push_back(2*i); } else if(b4[i]==2) { add.push_back(2*i+1); } else { add.push_back(2*i+1); add.push_back(2*i); } } sort(add.begin(),add.end()); reverse(add.begin(),add.end()); for(int i:add) { v.insert(v.begin()+i,v.size()); } return v; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...