제출 #1237994

#제출 시각아이디문제언어결과실행 시간메모리
1237994DeMen100ns캥거루 (CEOI16_kangaroo)C++20
100 / 100
71 ms94536 KiB
/*
Author : DeMen100ns (Vo Khac Trieu)
School: University of Science, VNU-HCM
Aim: 
- International Grandmaster Codeforces (2600) 
- ICPC World Final 2025
*/

#include <bits/stdc++.h>

#define int long long

using namespace std;

const long long INF = numeric_limits<long long>::max() / 2;
const int INF_int = 1e9 + 7;
const int MOD = 1e9 + 7;

void solve(){
    int n, cs, cf; cin >> n >> cs >> cf;
    vector <vector<array<int, 3>>> dp(n + 1, vector<array<int, 3>>(n + 1, {0, 0, 0}));

    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i){
        if (i + 1 == cs || i + 1 == cf){
            for(int c = 0; c <= i; ++c){
                for(int e = 0; e < 2; ++e){
                    dp[i][c][e] %= MOD;

                    dp[i + 1][c][e + 1] += dp[i][c][e] % MOD;
                    dp[i + 1][c + 1][e + 1] += dp[i][c][e] % MOD;
                }
            }
        } else {
            for(int c = 0; c <= i; ++c){
                for(int e = 0; e <= 2; ++e){
                    dp[i][c][e] %= MOD;

                    dp[i + 1][c + 1][e] += dp[i][c][e] * (c + 1 - e) % MOD;
                    dp[i + 1][c - 1][e] += dp[i][c][e] * (c - 1) % MOD;
                }
            }
        }
    }

    cout << dp[n][1][2] % MOD << '\n';
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1; // cin >> t;
    for(int test = 1; test <= t; ++test){
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...