Submission #638477

# Submission time Handle Problem Language Result Execution time Memory
638477 2022-09-06T08:52:18 Z TranGiaHuy1508 Permutation (APIO22_perm) C++17
89.8769 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

namespace {
	vector<int> primes = {2, 3, 5};

	deque<int> q;
	int lim;

	void mult(int x){
		for (int i = lim + x - 2; i >= lim; i--){
			q.push_back(i);
		}
		lim += x - 1;
	}

	void add(int x){
		for (int i = 0; i < x; i++) q.push_front(lim++);
	}

	void solve(ll k){
		if (k == 1) return;
		for (int i = (int)primes.size() - 1; i >= 0; i--){
			if (k % primes[i] == 0){
				solve(k / primes[i]);
				mult(primes[i]);
				return;
			}
		}
		if (k > 2 && (k - 2) % 5 == 0){
			solve(k - 2);
			add(2);
		}
		else{
			solve(k - 1);
			add(1);
		}
		return;
	}
}

vector<int> construct_permutation(ll k){
	lim = 0;
	solve(k);
	vector<int> v;
	while (!q.empty()){
		v.push_back(q.front());
		q.pop_front();
	}
	return v;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 1 ms 340 KB Partially correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Partially correct 2 ms 340 KB Partially correct
9 Partially correct 2 ms 340 KB Partially correct
10 Partially correct 2 ms 340 KB Partially correct
11 Partially correct 2 ms 340 KB Partially correct
12 Partially correct 2 ms 340 KB Partially correct
13 Partially correct 2 ms 340 KB Partially correct