Submission #897241

# Submission time Handle Problem Language Result Execution time Memory
897241 2024-01-02T19:26:07 Z d4xn Permutation (APIO22_perm) C++17
91.3333 / 100
1 ms 436 KB
#include "perm.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 5000, M = 100;
const ll L = 62;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> gen(vector<int> vt) {
	sort(vt.rbegin(), vt.rend());

	vector<int> p;
	for (int& i : vt) {
		//cerr << i << endl;
		if (p.empty()) {
			for (int j = 0; j < i; j++) {
				p.push_back(j);
				//cerr << "a " << j << endl;
			}
		}
		else {
			for (int j = i; j < p.size(); j++) {
				p[j]++;
			}
			p.push_back(p[i]-1);
			//cerr << "b " << p[i]-1 << endl;
		}
	}
	return p;
}

vector<int> construct_permutation(ll k)
{	
	vector<int> p, p2, vt;
	if (!k) return p;

		vt.clear();
		for (int j = L; j >= 0; j--) {
			if ((k >> j) & 1) {
				vt.push_back(j);
			}
		}

		p2 = gen(vt);
		if (p.empty() || p2.size() < p.size()) swap(p, p2);

	return p;
}

Compilation message

perm.cpp: In function 'std::vector<int> gen(std::vector<int>)':
perm.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |    for (int j = i; j < p.size(); j++) {
      |                    ~~^~~~~~~~~~
perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:39:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   39 |  if (!k) return p;
      |  ^~
perm.cpp:41:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   41 |   vt.clear();
      |   ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 436 KB Output is correct
10 Partially correct 1 ms 348 KB Partially correct
11 Partially correct 1 ms 348 KB Partially correct
12 Partially correct 1 ms 348 KB Partially correct
13 Partially correct 1 ms 348 KB Partially correct