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<bits/stdc++.h>
#include "perm.h"
using namespace std;
std::vector<int> construct_permutation(long long k)
{
vector< int > v;
if(k<=256){
long long p=2, s=1, r=0;
while(k>p){
p*=2;
s++;
}
s--;
long long a[100], dp[100];
while(r==0){
v.clear();
a[0]=0;
for(long long i=0; i<s; i++){
a[i+1]=i;
}
long long ind=0;
do{
for(long long i=0; i<=s; i++){
dp[i]=0;
}
long long ss=0;
dp[0]=1;
for(long long i=1; i<=s; i++){
for(long long j=0; j<=i-1; j++){
if(a[j]<=a[i]) dp[i]+=dp[j];
}
}
for(long long i=0; i<=s; i++){
ss+=dp[i];
}
if(ss==k){
ind++;
break;
}
}while(next_permutation(a+1, a+s+1));
if(ind==0) s++;
else{
r++;
}
}
for(long long i=1; i<=s; i++){
v.push_back(a[i]);
}
return v;
}
long long a[62], b[62];
long long m=k, f=-1, r;
for(long long i=0; i<=59; i++){
if(m%2==1){
a[i]=1;
}
m/=2;
}
for(long long i=59; i>=0; i--){
if(a[i]>0){
if(f==-1){
f=i;
r=f;
}
else{
b[i]=f;
f++;
}
}
}
for(long long i=0; i<=59; i++){
if(b[i]>0) v.push_back(b[i]);
if(i<r) v.push_back(i);
}
return v;
}
Compilation message (stderr)
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:75:3: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
75 | if(i<r) v.push_back(i);
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |