제출 #707540

#제출 시각아이디문제언어결과실행 시간메모리
707540600Mihnea순열 (APIO22_perm)C++17
10 / 100
6 ms340 KiB
#include "perm.h"
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

typedef long long ll;

int get_nr_bits(ll x)
{
	if (x == 0)
	{
		return 0;
	}
	assert(x >= 1);
	return get_nr_bits(x / 2) + x % 2;
}

vector<int> normalize(vector<int> v)
{
	map<int, int> mp;
	for (auto& x : v)
	{
		mp[x] = 0;
	}
	int y = 0;
	for (auto& it : mp)
	{
		it.second = y++;
	}
	for (auto& x : v)
	{
		x = mp[x];
	}
	return v;
}

vector<int> construct_permutation(ll total)
{
	if (total == 1)
	{
		return normalize({});
	}
	if (total == 2)
	{
		return normalize({ 0 });
	}
	if (total == 3)
	{
		return normalize({ 1, 0 });
	}
	if (total == 4)
	{
		return normalize({ 0, 1 });
	}
	assert(total >= 5);
	vector<int> sol = construct_permutation(total / 4);
	if (total % 4 == 0)
	{
		sol.push_back(100);
		sol.push_back(100 + 1);
	}
	if (total % 4 == 1)
	{
		sol.push_back(100);
		sol.push_back(100 + 1);
		sol.push_back(-1);
	}
	if (total % 4 == 2)
	{
		sol.push_back(100);
		sol.push_back(-1);
		sol.push_back(100 + 1);
	}
	if (total % 4 == 3)
	{
		sol.push_back(100);
		sol.push_back(-1);
		sol.push_back(100 + 1);
		sol.push_back(-2);
	}
	return normalize(sol);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...