Submission #1041351

# Submission time Handle Problem Language Result Execution time Memory
1041351 2024-08-01T22:20:15 Z MarwenElarbi Permutation (APIO22_perm) C++17
91.3333 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include "perm.h"
using namespace std;
#define pb push_back
std::vector<int> construct_permutation(long long k)
{
	k--;
	vector<int> tab;
	int cnt=0;
	int mx=0;
	for (int i = 62; i >= 0; --i)
	{
			while(mx==0&&k>=(1LL<<i)-1){
				mx=i;
				k-=(1LL<<i)-1;
				tab.pb(i);
			}	
		  while(mx>0&&k>=(1LL<<(i))){
				k-=(1LL<<(i));
				tab.pb(i+1);
			}	
	}
	sort(tab.rbegin(),tab.rend());
	vector<int> ans;
	int j=1;
	for (int i = 0; i < mx;++i)
	{
		ans.pb(tab.size()+i-1);
		while(j<tab.size()&&mx-i==tab[j]){
			ans.pb(tab.size()-j-1);
			j++;
		}
	}
	return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
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 |   while(j<tab.size()&&mx-i==tab[j]){
      |         ~^~~~~~~~~~~
perm.cpp:9:6: warning: unused variable 'cnt' [-Wunused-variable]
    9 |  int cnt=0;
      |      ^~~
# 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Partially correct 0 ms 348 KB Partially correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Partially correct 1 ms 348 KB Partially correct
9 Correct 1 ms 348 KB Output is correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 1 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct