Submission #1165482

#TimeUsernameProblemLanguageResultExecution timeMemory
1165482baldwin_huangPermutation (APIO22_perm)C++20
91.33 / 100
1 ms328 KiB
#include "perm.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> construct_permutation(long long k) {
	int greatest_power_of_two;
	for (int i = 63; i >= 0; i--) {
		if (k & (1LL << i)) {
			greatest_power_of_two = i;
			// cout << (1 << 63) << '\n';
			break;
		}
	}

	// cout << "Greatest: " << greatest_power_of_two << '\n';

	vector<int> pre_ans;

	long long diff = k - (1LL << greatest_power_of_two);

	int counter = greatest_power_of_two;
	for (int i = greatest_power_of_two - 1; i >= 0; i--) {
		pre_ans.push_back(i);
		if (diff & (1LL << i)) {
			pre_ans.push_back(counter);
			counter++;
		}
	}

	vector<int> ans;

	for (int i = pre_ans.size() - 1; i >= 0; i--) {
		ans.push_back(pre_ans[i]);
		// cout << pre_ans[i] << ' ';
	}
	// cout << '\n';

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...