# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730836 | Jarif_Rahman | Permutation (APIO22_perm) | C++17 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "perm.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> construct_permutation(ll k){
k--;
vector<int> sth;
int n = 0;
int P = 0;
while((1LL<<P)-1 <= k) P++;
P--;
k-=(1LL<<P)-1;
n+=P;
vector<int> s(P);
ll ss = 0;
vector<int> o;
for(int i = P-1; i > 0; i--) o.pb(i);
shuffle(o.begin(), o.end(), rng);
for(int i = 0; i < o.size(); i++){
int p = 1;
while((1LL<<p)-1 + ((1LL<<p)-1)*((1LL<<o[i])-1) <= k) p++;
p--;
k-=(1LL<<p)-1 + ((1LL<<p)-1)*((1LL<<o[i])-1);
s[o[i]] = p;
n+=p;
}
while(k > 0){
int p = 0;
while((1LL<<p)-1 <= k) p++;
p--;
k-=(1LL<<p)-1;
sth.pb(p);
n+=p;
}
vector<int> ans;
for(int x: sth){
for(int i = n-x; i < n; i++) ans.pb(i);
n-=x;
}
vector<int> anss, pp;
for(int i = n-P; i < n; i++) pp.pb(i);
n-=P;
if(!pp.empty()) anss.pb(pp[0]);
for(int i = 1; i < P; i++){
while(s[P-i]--) anss.pb(n-1), n--;
anss.pb(pp[i]);
}
ans.insert(ans.end(), anss.begin(), anss.end());
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |