This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MODULE 1000000007
int main() {
std::ifstream input;
input.open("kangaroo.in");
std::ofstream output;
output.open("kangaroo.out");
LL N, s, f;
input >> N >> s >> f;
LL dp[N+5][N+5]; memset(dp,0,sizeof(dp));
dp[1][1] = 1;
for (LL i = 2; i <= N; i++) {
for (LL j = 1; j <= N; j++) {
if (i == s || i == f) {
dp[i][j] += dp[i-1][j-1];
dp[i][j] %= MODULE;
dp[i][j] += dp[i-1][j];
dp[i][j] %= MODULE;
continue;
}
if (j-(i>s)-(i>f) > 0) {
dp[i][j] += (dp[i-1][j-1] * (j-(i>s)-(i>f))) % MODULE;
dp[i][j] %= MODULE;
}
dp[i][j] += (dp[i-1][j+1]*j) % MODULE;
dp[i][j] %= MODULE;
}
}
output << dp[N][1] << endl;
}
# | 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... |