Submission #983941

# Submission time Handle Problem Language Result Execution time Memory
983941 2024-05-16T08:19:14 Z vjudge1 Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 444 KB
#include <bits/stdc++.h>
#include "perm.h"

using namespace std;

const int N = 200;

int node = 0;
vector<int> g[N];
int a[N];

vector<int> b;
void dfs(int v) {
	b.push_back(a[v]);
	sort(g[v].begin(), g[v].end(), [](int x, int y) {
		return a[x] > a[y];
	});
	for (int to : g[v]) {
		dfs(to);
	}
}

vector<int> construct_permutation(long long k) {
	if (k == 1) 
		return {};
	while (node) {
		g[node].clear();
		a[node] = 0;
		node--;
	}
	b.clear();
	int mx = 63 - __builtin_clzll(k);
	node = 1;
	while (node < mx) {
		g[node].push_back(node + 1);
		++node;
	}
	
	int val = 0;
	for (int i = 1; i <= mx; i++) {
		a[i] = val++;
		if (i < mx && (k >> i & 1)) {
			g[i].push_back(++node);
			a[node] = val++;
		}
	}
	
	dfs(1);
	if (k & 1) {
		b.push_back(val++);
		for (int i = (int)b.size() - 2; i >= 0; i--)
			swap(b[i], b[i + 1]);
	}
	// for (int c : b) 
	// 	cout << c << ' ';
	// cout << '\n';
	return b;
}	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 ms 348 KB Partially correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Partially correct 1 ms 348 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 1 ms 344 KB Partially correct
12 Partially correct 1 ms 344 KB Partially correct
13 Partially correct 2 ms 348 KB Partially correct