Submission #573159

# Submission time Handle Problem Language Result Execution time Memory
573159 2022-06-06T07:31:55 Z Vanilla Permutation (APIO22_perm) C++17
91.3333 / 100
3 ms 340 KB
#include "perm.h"
#include <bits/stdc++.h>
using namespace std;

long long find (long long k) {
	for (long long i = 1; i < 63; i++){
		if ((1ll << i) > k) return i-1;
	}
}

std::vector<int> construct_permutation(long long k)
{
	vector <int> rs;
	long long pw [100] = {};
	k-=2;
	int sp = 1000;
	pw[0] = sp - 1;
	rs.push_back(sp);
	int step = 1;
	while (k != 0) {
		int hg = min(int(find(k)), step);
		if (pw[hg] == 0) {
			pw[hg] = pw[hg - 1] + sp;
		}
		rs.push_back(pw[hg]--);
		k-=(1ll << hg);
		step++;
	}
	vector <int> v = rs;
	sort(v.begin(), v.end());
	map <int, int> mp;
	for (int i = 0; i < v.size(); i++){
		mp[v[i]] = i;
	}
	for (int &i: rs){
		i = mp[i];
	}
	return rs;

}

// int main (){
// 	construct_permutation(12);
// }

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for (int i = 0; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
perm.cpp: In function 'long long int find(long long int)':
perm.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
    9 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Partially correct 2 ms 340 KB Partially correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Partially correct 3 ms 340 KB Partially correct
9 Correct 2 ms 340 KB Output is correct
10 Partially correct 3 ms 340 KB Partially correct
11 Partially correct 3 ms 340 KB Partially correct
12 Partially correct 2 ms 340 KB Partially correct
13 Partially correct 3 ms 340 KB Partially correct