結果

問題 No.1701 half price
ユーザー みーすけみーすけ
提出日時 2021-10-08 23:18:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 735 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 71,576 KB
実行使用メモリ 523,976 KB
最終ジャッジ日時 2023-09-30 13:10:11
合計ジャッジ時間 7,601 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
57,920 KB
testcase_01 WA -
testcase_02 MLE -
testcase_03 WA -
testcase_04 AC 125 ms
55,592 KB
testcase_05 AC 125 ms
56,212 KB
testcase_06 RE -
testcase_07 WA -
testcase_08 WA -
testcase_09 RE -
testcase_10 AC 122 ms
56,100 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 122 ms
55,876 KB
testcase_16 AC 124 ms
55,780 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 126 ms
56,080 KB
testcase_21 AC 127 ms
56,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int[][] dp = new int[n + 1][w + 1];

        dp[0][0] = 1;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= w; j++) {
                dp[i + 1][j] += dp[i][j];
                if (j >= a[i])
                    dp[i + 1][j] += dp[i][j - a[i]];
                if (j >= a[i] / 2)
                    dp[i + 1][j] += dp[i][j - a[i] / 2];
            }
        }

        System.out.println(dp[n][w]);
    }

}
0