結果

問題 No.1474 かさまJ
ユーザー gorugo30gorugo30
提出日時 2021-02-19 13:29:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,500 ms
コード長 1,466 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 171,096 KB
実行使用メモリ 10,156 KB
最終ジャッジ日時 2023-10-15 03:08:15
合計ジャッジ時間 5,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 4 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 269 ms
7,696 KB
testcase_06 AC 21 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 343 ms
7,856 KB
testcase_10 AC 34 ms
4,368 KB
testcase_11 AC 10 ms
4,368 KB
testcase_12 AC 6 ms
4,372 KB
testcase_13 AC 230 ms
8,392 KB
testcase_14 AC 106 ms
4,584 KB
testcase_15 AC 35 ms
4,368 KB
testcase_16 AC 37 ms
4,372 KB
testcase_17 AC 139 ms
6,444 KB
testcase_18 AC 264 ms
9,584 KB
testcase_19 AC 307 ms
10,028 KB
testcase_20 AC 323 ms
10,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

vector<long> fac(50000, 1);

long modpow(long x, long p, long mod){
    long ret = 1;
    while (p > 0){
        if (p & 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        p >>= 1;
    }
    return ret;
}

long nCr(long n, long r){
    if (n < r) return 0;
    return (((fac[n] * modpow(fac[n - r], MOD - 2, MOD)) % MOD) * modpow(fac[r], MOD - 2, MOD)) % MOD;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, MP, Mq, L;
    cin >> N >> MP >> Mq >> L;
    vector<int> S(N);
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }

    vector<vector<long>> dp(N + 1, vector<long>(Mq + 1, 0));
    dp[0][Mq] = 1;
    for (int i = 1; i <= min(S[0], Mq); i++){
        dp[1][Mq - i] = 1;
    }

    for (int i = 1; i < N; i++){
        for (int k = N; k >= 1; k--){
            long sum = 0;
            for (int r = Mq; r >= 0; r--){
                dp[k][r] = (dp[k][r] + sum) % MOD;
                sum = (sum + dp[k - 1][r]) % MOD;
                if (r + S[i] <= Mq) sum = (sum - dp[k - 1][r + S[i]] + MOD) % MOD;
            }
        }
    }

    for (int i = 1; i < 50000; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }

    long ans = 0;
    for (int m = 0; m <= Mq; m++){
        for (int x = 0; x <= N; x++){
            ans = (ans + dp[x][Mq - m] * nCr(MP + m - L * x + N - 1, N - 1)) % MOD;
        }
    }

    cout << ans << endl;
}
0