# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
67216 | Googal | Kangaroo (CEOI16_kangaroo) | C++14 | 80 ms | 23808 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;
typedef long long ll;
const int NMAX = 2 * 1e3 + 1e2;
const ll MOD = 1e9 + 7;
ll n, st, fn;
ll res;
ll dp[NMAX][NMAX];
int main()
{
ios::sync_with_stdio(false);
cin >> n >> st >> fn;
dp[0][0] = 1;
for(ll i = 1; i < n; i++) {
if(i == st || i == fn) {
for(int j = 0; j < i; j++)
(dp[i][j] += dp[i - 1][j]) %= MOD;
for(int j = 1; j < i; j++)
(dp[i][j - 1] += dp[i - 1][j] * j % MOD) %= MOD;
continue;
}
for(ll j = 0; j < i; j++) {
if(j >= 2){
(dp[i][j - 1] += dp[i - 1][j] * j % MOD * (j - 1) % MOD) %= MOD;
}
if(i >= st){
(dp[i][j - 1] += dp[i - 1][j] * j % MOD) %= MOD;
}
if(i >= fn){
(dp[i][j - 1] += dp[i - 1][j] * j % MOD) %= MOD;
}
(dp[i][j + 1] += dp[i - 1][j]) %= MOD;
}
}
cout << dp[n - 1][0] << '\n';
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... |