# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
740873 | LittleCube | Permutation (APIO22_perm) | C++17 | 2 ms | 344 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"
#ifndef EVAL
#include "perm_grader.cpp"
#endif
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
vector<int> construct_permutation(long long k)
{
vector<int> f, s, dp;
int n = 0;
ll ans = 0;
while (k > 1)
{
if (k % 3 == 0)
{
f.emplace_back(n + 1);
f.emplace_back(n);
n += 2;
k /= 3;
}
// else if(k % 3 == 0)
// {
// f.emplace_back(n);
// f.emplace_back(n + 1);
// n++;
// }
else if (k % 2 == 0)
{
f.emplace_back(n);
n++;
k /= 2;
}
else if (k % 5 == 0)
{
f.emplace_back(n + 1);
f.emplace_back(n + 2);
f.emplace_back(n);
n += 3;
k /= 5;
}
else if (k % 7 == 0)
{
f.emplace_back(n + 2);
f.emplace_back(n + 3);
f.emplace_back(n);
f.emplace_back(n + 1);
n += 4;
k /= 7;
}
else
{
s.emplace_back(n);
n++;
k--;
}
}
while (!s.empty())
{
f.emplace_back(s.back());
s.pop_back();
}
dp.resize(f.size());
for (int i = 0; i < f.size(); i++)
{
dp[i] = 1;
for (int j = 0; j < i; j++)
if (f[j] < f[i])
dp[i] += dp[j];
ans += dp[i];
}
cerr << ans << '\n';
return f;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |