Submission #984166

# Submission time Handle Problem Language Result Execution time Memory
984166 2024-05-16T10:54:41 Z Izaz Permutation (APIO22_perm) C++17
91.3333 / 100
3 ms 492 KB
#include <bits/stdc++.h>
using namespace std;
 
#define f first
#define s second
#define mn(a,b) min(a,b)
#define mx(a,b) max(a,b)
#define ll long long
ll power[61];
int re(ll k){
	for(int i = 0 ; i < 61 ;i++){
		if(power[i]>k)return i-1;
	}
	return 61;
}
vector<int>Solve(vector<int>vec , int Now_adding, ll k){
	if(k == 0 ){
		return vec;
	}
 
	int MAXI = re(k);
	vector<int>AL;
	for(int i = 0 ; i < vec.size();i++){
		if(i == MAXI){
			AL.push_back(Now_adding);
		}
		AL.push_back(vec[i]);
	}
	if(MAXI == vec.size())AL.push_back(Now_adding);
	return Solve(AL,Now_adding+1,k - (power[MAXI]));
}
vector<int> construct_permutation(long long  k)
{
	ll Num =  1;
	k -- ;
	power[0] = 1;
	for(int i = 1;i<=60;i++){
		Num*=2;
		power[i] = Num;
	}
	vector<vector<int>>Answer;
	vector<int>My_Answer;
	int Last =-1; 
	for(int i = 0 ; i < 10000;i ++) { 
		My_Answer.push_back(i);
		ll Num2 = (i - Last + 1);
		if(power[Num2]-1>k){
		k-=power[i-Last]-1;
		Answer.push_back(Solve(My_Answer,i+1,k));
		break;
		}
	}
	reverse(Answer.begin(),Answer.end());
	vector<int>Ans2;
	for(auto x:Answer){
		for(auto y: x)Ans2.push_back(y);
	}
   return Ans2;
}
// 

Compilation message

perm.cpp: In function 'std::vector<int> Solve(std::vector<int>, int, long long int)':
perm.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i = 0 ; i < vec.size();i++){
      |                  ~~^~~~~~~~~~~~
perm.cpp:29:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  if(MAXI == vec.size())AL.push_back(Now_adding);
      |     ~~~~~^~~~~~~~~~~~~
# 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 2 ms 344 KB Partially correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Partially correct 2 ms 344 KB Partially correct
9 Correct 2 ms 344 KB Output is correct
10 Partially correct 3 ms 492 KB Partially correct
11 Partially correct 2 ms 344 KB Partially correct
12 Partially correct 2 ms 348 KB Partially correct
13 Partially correct 3 ms 344 KB Partially correct