| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 603036 | tutis | 순열 (APIO22_perm) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "perm.h"
using namespace std;
#include <iostream>
#include <random>
#include <functional>
#include <map>
using ll = long long;
std::vector<int> construct_permutation(long long k, bool v)
{
if (k > 100)
{
if (k % 2 == 0)
{
vector<int>a = construct_permutation(k / 2, v);
a.push_back((int)a.size());
return a;
}
if (k % 4 == 3 && k > 1000)
{
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 && k > 1000)
{
vector<int>a = construct_permutation(k - 1, v);
for (int &i : a)
if (i >= 0)
i++;
a.push_back(0);
return a;
}
}
vector<int>ret = { -1};
vector<ll>dp = {1};
if (v)
{
assert(k >= 3);
vector<int>ret = { -1, 1, 0};
vector<ll>dp = {1, 1, 1};
}
for (int i : dp)
k -= i;
while (k != 0)
{
int sz = (int)ret.size();
for (int i = sz - 1; i >= 0; i--)
{
ll sum = 0;
for (int j = 0; j < (int)ret.size(); j++)
if (ret[j] < i)
sum += dp[j];
if (sum <= k)
{
k -= sum;
dp.push_back(sum);
for (int &j : ret)
if (j >= i)
j++;
ret.push_back(i);
break;
}
}
}
ret.erase(ret.begin());
return ret;
}
vector<int> construct_permutation(long long k)
{
return construct_permutation(k, false);
}
