Submission #982880

# Submission time Handle Problem Language Result Execution time Memory
982880 2024-05-14T22:19:22 Z vjudge1 Permutation (APIO22_perm) C++17
91.3333 / 100
2 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> construct_permutation(long long k) {
	k--;

	vector<int> arr;

	for (long long i = 1, j = 0; k; j++, i *= 2) {
		if (k % 2 == 1) {
			arr.push_back(1);
			k /= 2;
		} else {
			arr.push_back(2);
			k -= 2;
			k /= 2;
		}
	}

	//for(auto it: arr) cout<<it<<' ';

	int x = 0;

	for (int i = 0; i < arr.size(); i++, x++)
		if (arr[i] == 2) x++;

	vector<int> ans(x);

	for (int j = 0, k = x - 1, l = 0, p = 0; j < x; j++, p++) {
		if (arr[p] == 1) {
			ans[j] = l;
			l++;
		} else {
			ans[j]     = k;
			ans[j + 1] = l;
			k--;
			l++;
			j++;
		}
	}

	return ans;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < arr.size(); i++, x++)
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Partially correct 1 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 600 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 2 ms 504 KB Partially correct