Submission #985489

# Submission time Handle Problem Language Result Execution time Memory
985489 2024-05-18T01:02:52 Z Ghetto Permutation (APIO22_perm) C++17
0 / 100
5 ms 348 KB
#include "perm.h"
#include <bits/stdc++.h>
using lint = long long;
using namespace std;

vector<int> normalise(vector<int> x, int n_pos) {
	int diff = x.size() - n_pos - 1;
	for (int& y : x) y += diff;
	return x; 
}
vector<int> construct_permutation(lint k) {
	int max_bit = 0;
	for (int i = 0; i <= 60; i++) 
		if (k & (lint) powl(2, i)) max_bit = i;
	assert(max_bit != 0);

	vector<int> ans;
	for (int i = 1; i <= max_bit; i++) ans.push_back(i);
	int prev = 1;
	for (int bit = 0; bit <= 60; bit++) {
		if (!(k & (lint) powl(2, bit))) continue;
		if (bit == max_bit) continue;
		prev--;
		int diff = max_bit - bit;
		for (auto it = ans.begin(); it != ans.end(); it++) {
			if (*it != diff) continue;
			ans.insert(next(it, 1), prev);	
			break;
		}
	}
	
	// for (int x : ans) cout << x << " ";

	ans = normalise(ans, max_bit);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 5 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 5 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -