# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1242435 | hssaan_arif | Kangaroo (CEOI16_kangaroo) | C++20 | 1 ms | 320 KiB |
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
const int N = 1e3 + 5, M = 1e9 + 7 , LG = 20;
int n , dp[N][N][3] , s , t;
void solve(){
cin >> n >> s >> t;
if (s == 1 || t == 1){
dp[1][1][1] = 1;
}else{
dp[1][1][0] = 1;
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= i ; j++){
if (i + 1 == s || i + 1 == t){
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] += dp[i][j][k];
dp[i+1][j+1][k+1] %= M;
dp[i+1][j-1][k+1] %= M;
continue;
}
}
for (int k=0;k<3;k++){
dp[i+1][j + 1][k] += dp[i][j][k] * (j + 1 - k);
// dp[i+1][j] += dp[i][j] * 2 * j;
dp[i+1][j - 1][k] += dp[i][j][k] * (j - 1);
dp[i+1][j+1][k] %= M;
dp[i+1][j-1][k] %= M;
}
}
}
cout << dp[n][n][2]%M << endl;
}
signed main(){
freopen("kangaroo.in" , "r" , stdin);
freopen("kangaroo.out" , "w" , stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
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... |