# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
972161 | tamir1 | Permutation (APIO22_perm) | C++17 | 2 ms | 500 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 <iostream>
#define ll long long
using namespace std;
vector<int> construct_permutation(long long k)
{
ll t=1,i,j,idx,idx1,cnt[200],sum=0;
vector<ll> v,u;
while(true){
if(t>k) break;
v.push_back(t);
t=t*2;
}
fill(cnt,cnt+200,0);
while(k>0){
for(i=v.size()-1;i>=0;i--){
if(v[i]<=k){
u.push_back(i);
k-=v[i];
break;
}
}
}
sum=u[0];
idx1=0;
for(i=1;i<u.size();i++){
sum++;
cnt[u[i]]++;
}
idx=sum;
vector<int> ans(sum);
for(i=ans.size()-1;i>=0;i--){
if(cnt[sum-idx]>0){
ans[i]=idx1;
idx1++;
cnt[sum-idx]--;
}
else{
idx--;
ans[i]=idx;
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |