Submission #985490

# Submission time Handle Problem Language Result Execution time Memory
985490 2024-05-18T01:04:13 Z Ghetto Permutation (APIO22_perm) C++17
91.3333 / 100
8 ms 440 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 = 60; bit >= 0; 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 << " ";
	// cout << endl;

	ans = normalise(ans, max_bit);
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 6 ms 348 KB Output is correct
4 Correct 6 ms 440 KB Output is correct
5 Partially correct 6 ms 348 KB Partially correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Partially correct 7 ms 348 KB Partially correct
9 Correct 7 ms 348 KB Output is correct
10 Partially correct 8 ms 348 KB Partially correct
11 Partially correct 7 ms 348 KB Partially correct
12 Partially correct 8 ms 348 KB Partially correct
13 Partially correct 7 ms 348 KB Partially correct