# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
318187 | a14789654 | Kangaroo (CEOI16_kangaroo) | C++17 | 34 ms | 14316 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.
///https://oj.uz/problem/view/CEOI16_kangaroo
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2007, MOD = 1e9 + 7;
int cs, cf, n, f[MAXN][MAXN];
void add(int &a, int b)
{
a += b;
if (a >= MOD) a -= MOD;
}
int main()
{
if (fopen("tst.inp", "r"))
{
freopen("tst.inp", "r", stdin);
freopen("tst.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> cs >> cf;
if (cs > cf) swap(cs, cf);
f[1][0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 0; j <= i; ++j)
if (i != cs && i != cf)
{
if (i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j * (j - 1) % MOD);
if (i < n && j < n) add(f[i + 1][j + 1], f[i][j]);
if (i > cs && i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
if (i > cf && i < n && j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
}
else
{
add(f[i + 1][j], f[i][j]);
if (j) add(f[i + 1][j - 1], 1LL * f[i][j] * j % MOD);
}
cout << f[n][0];
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |