Submission #578418

# Submission time Handle Problem Language Result Execution time Memory
578418 2022-06-16T17:57:20 Z 1zaid1 Permutation (APIO22_perm) C++17
91.3333 / 100
4 ms 456 KB
#include "perm.h"
#include "bits/stdc++.h"
using namespace std;

std::vector<int> construct_permutation(long long k)
{
	int p = 1;
	vector<int> ans;
	int mx = 1, mn = -1;
	vector<int> steps;
	while (k) {
		if (k%2) steps.push_back(1);
		steps.push_back(0);
		k /= 2;
	}

	steps.pop_back();
	steps.pop_back();
	reverse(steps.begin(), steps.end());
	for (int i:steps) {
		if (i) ans.push_back(mn--);
		else ans.push_back(mx++);
	}

	map<int, int> fr;
	vector<int> tmp = ans;
	int ind = 0;
	sort(tmp.begin(), tmp.end());
	for (int i:tmp) {
		fr[i] = ind++;
	}

	for (int&i:ans) i = fr[i];
	return ans;
}
/*
1 2 4 5 10 11 22 23
{}
{0 1 -1 2 -2 3 -3}
{3 4 2 5 1 6 0}
{}
*/

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:7:6: warning: unused variable 'p' [-Wunused-variable]
    7 |  int p = 1;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 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 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Partially correct 4 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 3 ms 340 KB Partially correct
13 Partially correct 3 ms 456 KB Partially correct