Submission #744344

#TimeUsernameProblemLanguageResultExecution timeMemory
744344amirhoseinfar1385Permutation (APIO22_perm)C++17
71.22 / 100
15 ms1020 KiB
//#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> construct_permutation(long long k)
{
	k--;
	vector<int>res;
	long long sz=0;
	long long fk=k;
	for(long long j=62;j>=1;j--){
		while(k>=((1ll<<j)-1)){
			sz+=j;
		//	cout<<k<<endl;
			k-=((1ll)<<j)-1;
		}
	}	
	res.resize(sz);
	long long now=sz;
	k=fk;
	long long noww=0;
	for(long long j=62;j>=1;j--){
		while(k>=((1ll<<j)-1)){
			long long fake=now-j;
			for(long long h=0;h<j;h++,fake++,noww++){
				res[noww]=fake;
			}
			now-=j;
		//	cout<<k<<endl;
			k-=(1ll<<j)-1;
		}
	}
	//for(auto x:res){
	//	cout<<x<<" ";
	//}
	//cout<<"\n";
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...