# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731437 | ogibogi2004 | Permutation (APIO22_perm) | C++17 | 4 ms | 384 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 ll long long
using namespace std;
vector<int> construct_permutation(long long k)
{
vector<int>ret;
ll cur=1;
for(int i=0;;i++)
{
ret.push_back(i);
cur*=2;
if(cur>k)
{
ret.pop_back();
cur/=2;
break;
}
}
ll diff=k-cur;
int cnt=-1;
for(ll j=60;j>=0;j--)
{
if(diff&(1ll<<j))
{
//insert new number cnt where there will be j numbers after it
vector<int>ret1;
reverse(ret.begin(),ret.end());
for(int l=0;l<j;l++)ret1.push_back(ret[l]);
ret1.push_back(cnt);
for(int l=j;l<ret.size();l++)ret1.push_back(ret[l]);
cnt--;
ret=ret1;
reverse(ret.begin(),ret.end());
}
}
for(int i=0;i<ret.size();i++)
{
ret[i]-=cnt+1;
}
/*for(auto xd:ret)cout<<xd<<" ";
cout<<endl;*/
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |