Submission #968397

#TimeUsernameProblemLanguageResultExecution timeMemory
96839712345678Permutation (APIO22_perm)C++17
0 / 100
0 ms348 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; #define ll long long int mx, cnt; ll p[62]; vector<int> res, l; std::vector<int> construct_permutation(long long k) { p[0]=1; for (int i=1; i<62; i++) p[i]=p[i-1]*2; if (k==1) return vector<int> {}; mx=cnt=0; res.clear(); l.clear(); ll tmp=k; while (tmp>0) { if (tmp%2==1) mx=max(mx, cnt); tmp/=2; cnt++; } ll vl=k-p[mx]; for (int i=0; i<mx; i++) res.push_back(i); if (vl==0) return res; vl--; cnt=0; while (vl>0) { if (vl%2==1) l.push_back(cnt); vl/=2; cnt++; } for (auto x:l) res[x]--; for (int i=0; i<mx; i++) res[i]++; res.push_back(l.size()); return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...