# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
897241 | d4xn | Permutation (APIO22_perm) | C++17 | 1 ms | 436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |