# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
860904 | blackslex | Kangaroo (CEOI16_kangaroo) | C++17 | 40 ms | 55132 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 int N = 2005, M = 1e9 + 7;
ll n, cs, cf, dp[N][N][3];
int main() {
scanf("%lld %lld %lld", &n, &cs, &cf);
if (cs == 1 || cf == 1) dp[1][1][1] = 1;
else dp[1][1][0] = 1;
for (int i = 1; i <= n; i++) {
if (i + 1 == cs || i + 1 == cf) {
for (int j = 1; j <= i; j++) {
for (int k = 0; k < 2; k++) {
dp[i + 1][j + 1][k + 1] += dp[i][j][k]; dp[i + 1][j + 1][k + 1] %= M; // fix, no merge
dp[i + 1][j][k + 1] += dp[i][j][k]; dp[i + 1][j][k + 1] %= M; // fix, merge
}
}
} else {
for (int j = 1; j <= i; j++) {
for (int k = 0; k < 3; k++) {
dp[i + 1][j + 1][k] += (j + 1 - k) * dp[i][j][k]; dp[i + 1][j + 1][k] %= M; // insert, no merge
dp[i + 1][j - 1][k] += (j - 1) * dp[i][j][k]; dp[i + 1][j - 1][k] %= M; // insert, merge
}
}
}
}
printf("%lld", dp[n][1][2]);
}
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... |