Submission #897241

#TimeUsernameProblemLanguageResultExecution timeMemory
897241d4xnPermutation (APIO22_perm)C++17
91.33 / 100
1 ms436 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...