結果

問題 No.1238 選抜クラス
ユーザー tentententen
提出日時 2023-04-25 09:53:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,186 bytes
コンパイル時間 2,689 ms
コンパイル使用メモリ 89,708 KB
実行使用メモリ 46,468 KB
最終ジャッジ日時 2024-04-26 16:59:45
合計ジャッジ時間 6,614 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,984 KB
testcase_01 AC 54 ms
36,812 KB
testcase_02 AC 53 ms
37,068 KB
testcase_03 AC 54 ms
37,176 KB
testcase_04 AC 51 ms
37,320 KB
testcase_05 AC 51 ms
37,332 KB
testcase_06 AC 51 ms
37,016 KB
testcase_07 AC 51 ms
36,856 KB
testcase_08 AC 52 ms
36,868 KB
testcase_09 AC 53 ms
37,484 KB
testcase_10 AC 53 ms
36,972 KB
testcase_11 AC 53 ms
37,328 KB
testcase_12 AC 55 ms
37,180 KB
testcase_13 AC 51 ms
36,948 KB
testcase_14 AC 51 ms
37,088 KB
testcase_15 AC 53 ms
37,184 KB
testcase_16 AC 53 ms
36,880 KB
testcase_17 AC 97 ms
46,224 KB
testcase_18 AC 84 ms
45,684 KB
testcase_19 AC 67 ms
44,636 KB
testcase_20 AC 90 ms
42,228 KB
testcase_21 AC 66 ms
40,696 KB
testcase_22 AC 80 ms
45,364 KB
testcase_23 AC 81 ms
45,404 KB
testcase_24 AC 69 ms
44,944 KB
testcase_25 AC 83 ms
45,560 KB
testcase_26 AC 91 ms
46,468 KB
testcase_27 AC 79 ms
45,372 KB
testcase_28 AC 82 ms
45,508 KB
testcase_29 AC 76 ms
45,584 KB
testcase_30 AC 57 ms
37,652 KB
testcase_31 AC 64 ms
38,496 KB
testcase_32 AC 63 ms
39,388 KB
testcase_33 AC 52 ms
36,928 KB
testcase_34 AC 82 ms
41,344 KB
testcase_35 AC 54 ms
37,744 KB
testcase_36 AC 53 ms
37,368 KB
testcase_37 AC 58 ms
37,580 KB
testcase_38 AC 78 ms
41,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] values;
    static int[][] dp;
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt() - k;
        }
      Arrays.sort(values);
        dp = new int[n][n * 100 + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println((dfw(n - 1, 0) - 1 + MOD) % MOD);
    }
    
    static int dfw(int idx, int v) {
        if (v < 0) {
            return 0;
        }
        if (idx < 0) {
            return 1;
        }
        if (dp[idx][v] < 0) {
            dp[idx][v] = (dfw(idx - 1, v) + dfw(idx - 1, v + values[idx])) % MOD;
        }
        return dp[idx][v];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0