結果

問題 No.1457 ツブ消ししとるなHard
ユーザー tentententen
提出日時 2021-04-13 15:41:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 2,185 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 51,948 KB
最終ジャッジ日時 2023-09-12 07:41:44
合計ジャッジ時間 4,624 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,304 KB
testcase_01 AC 42 ms
49,284 KB
testcase_02 AC 43 ms
49,308 KB
testcase_03 AC 42 ms
49,268 KB
testcase_04 AC 84 ms
50,000 KB
testcase_05 AC 83 ms
51,948 KB
testcase_06 AC 84 ms
51,936 KB
testcase_07 AC 44 ms
49,700 KB
testcase_08 AC 42 ms
49,348 KB
testcase_09 AC 44 ms
49,452 KB
testcase_10 AC 44 ms
49,272 KB
testcase_11 AC 43 ms
49,360 KB
testcase_12 AC 54 ms
50,228 KB
testcase_13 AC 46 ms
49,252 KB
testcase_14 AC 44 ms
49,428 KB
testcase_15 AC 46 ms
49,236 KB
testcase_16 AC 45 ms
49,412 KB
testcase_17 AC 44 ms
49,348 KB
testcase_18 AC 43 ms
49,300 KB
testcase_19 AC 80 ms
51,728 KB
testcase_20 AC 44 ms
49,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        int count = 0;
        int total = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a >= x) {
                count++;
                total += a;
            } else if (a > y) {
                list.add(a);
            }
        }
        if (count == m) {
            if (m * z == total) {
                System.out.println(1);
            } else {
                System.out.println(0);
            }
            return;
        } else if (count > m) {
            System.out.println("Handicapped");
            return;
        }
        m -= count;
        long[][] dp = new long[m + 1][list.size() * 50 + 1];
        dp[0][0] = 1;
        for (int i = 0; i < list.size(); i++) {
            int a = list.get(i);
            for (int j = Math.min(i, m - 1); j >= 0 ; j--) {
                for (int k = j * 50; k >= 0; k--) {
                    dp[j + 1][k + a] += dp[j][k];
                }
            }
        }
        long ans = 0;
        for (int i = 1; i <= m; i++) {
            if ((i + count) * z - total >= 0 && (i + count) * z - total < dp[i].length) {
                ans += dp[i][(i + count) * z - total];
            }
        }
        System.out.println(ans);
    }
}
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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0