Submission #980841

# Submission time Handle Problem Language Result Execution time Memory
980841 2024-05-12T13:36:28 Z Malix Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 604 KB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair

ll INF=1e18+10;

std::vector<int> construct_permutation(long long k)
{
	if(k==1)return {};
	//k--;
	vi ans;
	int pos=-1;
	vector<ll> a(70,INF);
	REP(i,0,64)a[i]=pow(2,i);
	bool flag=1;

	int it=lower_bound(a.begin(),a.end(),k)-a.begin();
	if(a[it]!=k)it--;
	k-=a[it];
	pos+=it;
	int pos2=pos;
	while(it){
	ans.PB(pos);
		pos--;
		it--;
	}
	pos=pos2;
	reverse(ans.begin(),ans.end());
	while(k){
		pos++;
		int it=lower_bound(a.begin(),a.end(),k)-a.begin();
		if(a[it]!=k)it--;
		k-=a[it];
		ans.insert(ans.begin()+it,pos);
	}
	//REP(i,0,ans.size())cout<<ans[i]<<" ";
	return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:30:10: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'long long int' [-Wsign-compare]
   30 |  if(a[it]!=k)it--;
perm.cpp:44:11: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<long long unsigned int>, long long unsigned int>::value_type' {aka 'long long unsigned int'} and 'long long int' [-Wsign-compare]
   44 |   if(a[it]!=k)it--;
perm.cpp:27:7: warning: unused variable 'flag' [-Wunused-variable]
   27 |  bool flag=1;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Partially correct 1 ms 348 KB Partially correct
6 Correct 1 ms 344 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 2 ms 604 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct