結果

問題 No.1238 選抜クラス
ユーザー tentententen
提出日時 2022-08-16 08:54:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 702 ms / 2,000 ms
コード長 1,766 bytes
コンパイル時間 2,650 ms
コンパイル使用メモリ 77,908 KB
実行使用メモリ 476,452 KB
最終ジャッジ日時 2024-04-14 04:04:55
合計ジャッジ時間 14,321 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
50,372 KB
testcase_01 AC 56 ms
50,420 KB
testcase_02 AC 66 ms
52,696 KB
testcase_03 AC 54 ms
50,388 KB
testcase_04 AC 55 ms
50,108 KB
testcase_05 AC 55 ms
50,084 KB
testcase_06 AC 55 ms
50,404 KB
testcase_07 AC 60 ms
50,372 KB
testcase_08 AC 66 ms
52,676 KB
testcase_09 AC 89 ms
60,664 KB
testcase_10 AC 64 ms
52,588 KB
testcase_11 AC 77 ms
55,936 KB
testcase_12 AC 80 ms
55,560 KB
testcase_13 AC 69 ms
55,332 KB
testcase_14 AC 67 ms
52,676 KB
testcase_15 AC 90 ms
60,492 KB
testcase_16 AC 77 ms
56,016 KB
testcase_17 AC 613 ms
476,432 KB
testcase_18 AC 592 ms
470,020 KB
testcase_19 AC 702 ms
470,060 KB
testcase_20 AC 545 ms
470,120 KB
testcase_21 AC 537 ms
476,172 KB
testcase_22 AC 452 ms
476,388 KB
testcase_23 AC 442 ms
470,072 KB
testcase_24 AC 441 ms
470,168 KB
testcase_25 AC 437 ms
470,172 KB
testcase_26 AC 568 ms
472,688 KB
testcase_27 AC 591 ms
476,452 KB
testcase_28 AC 561 ms
470,140 KB
testcase_29 AC 551 ms
476,448 KB
testcase_30 AC 127 ms
87,616 KB
testcase_31 AC 205 ms
196,976 KB
testcase_32 AC 381 ms
371,488 KB
testcase_33 AC 61 ms
50,048 KB
testcase_34 AC 402 ms
370,552 KB
testcase_35 AC 148 ms
112,956 KB
testcase_36 AC 106 ms
63,764 KB
testcase_37 AC 133 ms
92,236 KB
testcase_38 AC 539 ms
470,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static int[] values;
    static int[][][] dp;
    static int k;
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new int[n][n + 1][10001];
        for (int[][] arr1 : dp) {
            for (int[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        System.out.println(dfw(n - 1, 0, 0));
    }
    
    static int dfw(int idx, int count, int v) {
        if (idx < 0) {
            if (count > 0 && count * k <= v) {
                return 1;
            } else {
                return 0;
            }
        }
        if (dp[idx][count][v] < 0) {
            dp[idx][count][v] = (dfw(idx - 1, count, v) + dfw(idx - 1, count + 1, v + values[idx])) % MOD;
        }
        return dp[idx][count][v];
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0