Submission #603038

# Submission time Handle Problem Language Result Execution time Memory
603038 2022-07-23T14:30:57 Z tutis Permutation (APIO22_perm) C++17
10 / 100
1 ms 300 KB
#include "perm.h"
using namespace std;
#include <iostream>
#include <random>
#include <functional>
#include <cassert>
#include <map>
using ll = long long;
std::vector<int> construct_permutation(long long k, bool v)
{
	if (k > 100)
	{
		if (k % 2 == 0)
		{
			vector<int>a = construct_permutation(k / 2, v);
			a.push_back((int)a.size());
			return a;
		}
		if (k % 4 == 3 && k > 1000)
		{
			vector<int>a = construct_permutation(k - 3, true);
			for (int &i : a)
				if (i >= 2)
					i++;
			a.push_back(2);
			return a;
		}
		if (k % 2 == 1 && k > 1000)
		{
			vector<int>a = construct_permutation(k - 1, v);
			for (int &i : a)
				if (i >= 0)
					i++;
			a.push_back(0);
			return a;
		}
	}
	vector<int>ret = { -1};
	vector<ll>dp = {1};
	if (v)
	{
		assert(k >= 3);
		vector<int>ret = { -1, 1, 0};
		vector<ll>dp = {1, 1, 1};
	}
	for (int i : dp)
		k -= i;
	while (k != 0)
	{
		int sz = (int)ret.size();
		for (int i = sz - 1; i >= 0; i--)
		{
			ll sum = 0;
			for (int j = 0; j < (int)ret.size(); j++)
				if (ret[j] < i)
					sum += dp[j];
			if (sum <= k)
			{
				k -= sum;
				dp.push_back(sum);
				for (int &j : ret)
					if (j >= i)
						j++;
				ret.push_back(i);
				break;
			}
		}
	}
	ret.erase(ret.begin());
	return ret;
}

vector<int> construct_permutation(long long k)
{
	return construct_permutation(k, false);
}
# 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 Incorrect 1 ms 300 KB Output isn't correct
4 Halted 0 ms 0 KB -