Submission #586530

# Submission time Handle Problem Language Result Execution time Memory
586530 2022-06-30T11:23:42 Z jamezzz Permutation (APIO22_perm) C++17
0 / 100
1 ms 212 KB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(),x.end()
#define pb push_back
typedef long long ll;

vector<int> construct_permutation(ll k){
	vector<int> b4;
	while(k){
		b4.pb((int)k%4);
		k/=4;
	}
	
	vector<double> ans;
	if(b4.back()==2)ans.pb(0);
	else if(b4.back()==3)ans.pb(1),ans.pb(0);
	b4.pop_back();
	
	while(!b4.empty()){
		if(b4.back()==0)ans.pb(1e9),ans.pb(1e9+1);
		else if(b4.back()==1)ans.pb(1e9),ans.pb(1e9+1),ans.pb(-1);
		else if(b4.back()==2)ans.pb(1e9),ans.pb(-1),ans.pb(1e9+1);
		else{
			int p0,p1;
			for(int i=0;i<ans.size();++i){
				if(ans[i]==0)p0=i;
				if(ans[i]==1)p1=i;
			}
			if(p1<p0)ans.pb(1e9),ans.pb(1e9+1),ans.pb(1.5);
			else ans.pb(1e9),ans.pb(-1),ans.pb(1e9+1),ans.pb(-2);
		}
		b4.pop_back();
		
		vector<double> srt;
		for(auto x:ans)srt.pb(x);
		sort(all(srt));
		for(auto &x:ans)x=lower_bound(all(srt),x)-srt.begin();
	}
	
	return vector<int>(all(ans));
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(ll)':
perm.cpp:27:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for(int i=0;i<ans.size();++i){
      |                ~^~~~~~~~~~~
perm.cpp:31:4: warning: 'p1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |    if(p1<p0)ans.pb(1e9),ans.pb(1e9+1),ans.pb(1.5);
      |    ^~
perm.cpp:31:4: warning: 'p0' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -