結果

問題 No.1474 かさまJ
ユーザー gorugo30gorugo30
提出日時 2021-02-19 22:19:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,459 ms / 2,500 ms
コード長 1,893 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 74,820 KB
実行使用メモリ 65,072 KB
最終ジャッジ日時 2023-10-15 02:35:58
合計ジャッジ時間 14,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,116 KB
testcase_01 AC 120 ms
56,332 KB
testcase_02 AC 136 ms
53,972 KB
testcase_03 AC 126 ms
55,952 KB
testcase_04 AC 121 ms
56,616 KB
testcase_05 AC 1,196 ms
60,984 KB
testcase_06 AC 222 ms
58,656 KB
testcase_07 AC 127 ms
56,068 KB
testcase_08 AC 130 ms
55,520 KB
testcase_09 AC 1,459 ms
60,724 KB
testcase_10 AC 276 ms
58,720 KB
testcase_11 AC 162 ms
56,096 KB
testcase_12 AC 146 ms
56,116 KB
testcase_13 AC 982 ms
60,788 KB
testcase_14 AC 552 ms
58,008 KB
testcase_15 AC 274 ms
56,304 KB
testcase_16 AC 286 ms
56,100 KB
testcase_17 AC 727 ms
60,760 KB
testcase_18 AC 1,103 ms
60,484 KB
testcase_19 AC 1,257 ms
64,976 KB
testcase_20 AC 1,317 ms
65,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main{
    private static long MOD = 1000000007;
    private static long fac[] = new long[50000];
    private static long modpow(long x, long p){
        long ret = 1;
        while (p > 0){
            if (p % 2 == 1) ret = (ret * x) % MOD;
            x = (x * x) % MOD;
            p >>= 1;
        }
        return ret;
    }
    private static long nCr(int n, int r){
        if (n < r) return 0;
        return (((fac[n] * modpow(fac[n - r], MOD - 2)) % MOD) * modpow(fac[r], MOD - 2)) % MOD;
    }
    private static int min(int x, int y){
        if (x < y) return x;
        return y;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int MP = sc.nextInt();
        int Mq = sc.nextInt();
        int L = sc.nextInt();
        int S[] = new int[N];
        for (int i = 0; i < N; i++){
            S[i] = sc.nextInt();
        }
        
        long dp[][] = new long[N + 1][Mq + 1];
        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;
                }
            }
        }

        fac[0] = 1;
        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;
            }
        }
        System.out.println(ans);
    }
}
0