# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
605440 | MadokaMagicaFan | Kangaroo (CEOI16_kangaroo) | C++14 | 0 ms | 340 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 "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e9;
const int md1 = 1e9+7;
const int md2 = 998244353;
#define sz(v) ((int)v.size())
#define pb push_back
#define pry cout << "YES\n"
#define prn cout << "NO\n"
#define endl '\n'
#define fst first
#define scn second
#define ONPC
const int N = 2000;
ll dp[N+1][N+5];
#ifdef ONPC
void
solve()
{
int n, s, t;
cin >> n >> s >> t;
if (s > t) swap(s,t);
s -= 2;
t -= 2;
dp[0][1] = 1;
for (int i = 0; i < n-2; ++i) {
for (ll j = 1; j < n+1; ++j) {
if (i < s) dp[i+1][j] = (dp[i][j-1] + (j+1)*j*dp[i][j+1]) % md1;
else if (i == s) dp[i+1][j] = (dp[i][j-1] + j*dp[i][j]) % md1;
else if (i > t) dp[i+1][j] = (dp[i][j-1] + j*j*dp[i][j+1]) % md1;
else if (i == t) dp[i+1][j] = (dp[i][j] + j*dp[i][j+1]) % md1;
else dp[i+1][j] = (dp[i][j-1] + (j+1)*j*dp[i][j+1]) % md1;
}
}
/* for (int i = 0; i < n; ++i) { */
/* for (int j = 0; j < n; ++j) { */
/* cout << dp[j][i] << ' '; */
/* } */
/* */
/* cout << endl; */
/* } */
cout << dp[n-2][1] << endl;
}
int32_t
main(int argc, char **argv)
{
if (argc >= 2) {
freopen(argv[1], "r", stdin);
} else
ios_base::sync_with_stdio(0);cin.tie(0);
int t = 1;
/* cin >> t; */
while(t--)
solve();
}
#endif
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... |