#include "perm.h"
using namespace std;
#include <iostream>
#include <random>
#include <functional>
#include <cassert>
#include <map>
using ll = long long;
std::vector<int> construct_permutation(long long k, bool v)
{
if (k == 1)
return {};
if (k == 3)
return {1, 0};
if (k == 4)
return {2, 1, 0};
if (k % 2 == 0)
{
vector<int>a = construct_permutation(k / 2, v);
a.push_back((int)a.size());
return a;
}
if (k % 4 == 3)
{
vector<int>a = construct_permutation(k - 3, true);
for (int &i : a)
if (i >= 2)
i++;
a.push_back(2);
return a;
}
if (k % 2 == 1)
{
vector<int>a = construct_permutation(k - 1, v);
a.insert(a.begin(), (int)a.size());
return a;
}
assert(false);
return {};
}
vector<int> construct_permutation(long long k)
{
return construct_permutation(k, false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
296 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
2 ms |
300 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
300 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
3 ms |
296 KB |
Output is correct |