# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
109085 | DystoriaX | Kangaroo (CEOI16_kangaroo) | C++14 | 187 ms | 47600 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;
int n, cs, cf;
int dp[2010][2010][3];
const int MOD = 1e9 + 7;
int add(long long a, long long b){
return (a + b) % MOD;
}
int mul(long long a, long long b){
return (a * b) % MOD;
}
int main(){
scanf("%d%d%d", &n, &cs, &cf);
dp[0][0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= 2; k++){
if(k > j) continue;
int v = dp[i - 1][j][k];
if(i != cf && i != cs){
dp[i][j - 1][k] = add(dp[i][j - 1][k], mul(v, j - 1));
dp[i][j + 1][k] = add(dp[i][j + 1][k], mul(v, j + 1 - k));
} else if (k < 2) {
dp[i][j][k + 1] = add(dp[i][j][k + 1], v);
dp[i][j + 1][k + 1] = add(dp[i][j + 1][k + 1], v);
}
}
}
}
printf("%d\n", dp[n][1][2]);
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... |