# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1220911 | QuocSensei | Kangaroo (CEOI16_kangaroo) | C++20 | 45 ms | 31816 KiB |
#include <bits/stdc++.h>
#define ll long long
#define el cout << '\n'
using namespace std;
const int maxn = 2e3;
const int MOD = 1e9 + 7;
int n, s, t;
ll dp[maxn + 10][maxn + 10];
void add(ll &a, ll b)
{
b %= MOD;
a += b;
if (a >= MOD)
a -= MOD;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("KANGAROO.INP", "r"))
{
freopen("KANGAROO.INP", "r", stdin);
freopen("KANGAROO.OUT", "w", stdout);
}
cin >> n >> s >> t;
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
{
if (i == s)
{
add(dp[i][j], dp[i - 1][j - 1]);
if (i > t && i < n)
add(dp[i][j], (j - 1) * dp[i - 1][j]);
else if (i > t)
add(dp[i][j], dp[i - 1][j]);
else
add(dp[i][j], j * dp[i - 1][j]);
}
else if (i == t)
{
add(dp[i][j], dp[i - 1][j - 1]);
if (i > s && i < n)
add(dp[i][j], (j - 1) * dp[i - 1][j]);
else if (i > s)
add(dp[i][j], dp[i - 1][j]);
else
add(dp[i][j], j * dp[i - 1][j]);
}
else
{
add(dp[i][j], dp[i - 1][j - 1]);
if (i > max(s, t) && i < n)
add(dp[i][j], j * (j - 1) * dp[i - 1][j + 1]);
else if (i > max(s, t))
add(dp[i][j], dp[i - 1][j + 1]);
else if (i > min(s, t))
add(dp[i][j], j * j * dp[i - 1][j + 1]);
else
add(dp[i][j], j * (j + 1) * dp[i - 1][j + 1]);
}
}
// for (int i = 1; i <= n; i++)
// {
// for (int j = 1; j <= n; j++)
// cout << dp[i][j] << ' ';
// el;
// }
cout << dp[n][1];
}
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... |