Submission #1362730

#TimeUsernameProblemLanguageResultExecution timeMemory
1362730serendipitousPermutation (APIO22_perm)C++20
71.22 / 100
4 ms1508 KiB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

std::vector<int> construct_permutation(long long k)
{


	ll kcpy = k-1;
	vector<int> sizes;
	int len = 0;
    int e = __lg(k)+1;
    while(kcpy > 0) {
        while((1LL << e)-1 > kcpy) --e;
        len += e;
		sizes.push_back(e);
        kcpy -= (1LL << e)-1;
    }

	// cerr << "len = " << len << endl;

	vector<int> p;
	int end = len;
	for(int s: sizes) {
		for(int i = end - s + 1; i <= end; ++i) {
			p.push_back(i-1);
		}
		end -= s;
	}
	return p;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...