Submission #1035253

# Submission time Handle Problem Language Result Execution time Memory
1035253 2024-07-26T07:54:35 Z amine_aroua Permutation (APIO22_perm) C++17
0 / 100
1000 ms 348 KB
#include "perm.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
std::vector<int> construct_permutation(long long k)
{
	int sz = 10000;
	vector<int> best;
	for(ll l = 1 ;l < 61 ;l++)
	{
		ll x = k + l - 1;
		if(__builtin_popcountll(x) <= l)
		{
			int n = 0;
			vector<int> bits;
			for(ll i = 0 ; i < 61 ; i++)
			{
				if((1ll<<i) & x)
				{
					bits.push_back(i);
				}
			}
			while ((int)bits.size() < l)
			{
				for(int i = 0 ; (int)bits.size()< l && i < (int)bits.size() ; i++)
				{
					int bit = bits[i];
					if(bit > 1)
					{
						bits[i] = --bit;
						bits.push_back(bits[i]);
					}
				}
			}
			for(auto bit : bits)
				n+=bit;
			n--;
			vector<int> perm;
			for(auto i : bits)
			{
				for(int j = n - i + 1 ; j <= n ; j++)
				{
					perm.push_back(j);
				}
				n-=i;
			}
			if((int)perm.size() < sz)
			{
				sz = (int)perm.size();
				best = perm;
			}
		}
	}
	return best;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -