結果

問題 No.107 モンスター
ユーザー tentententen
提出日時 2020-12-22 15:37:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 966 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 77,284 KB
実行使用メモリ 57,688 KB
最終ジャッジ日時 2023-10-21 12:57:27
合計ジャッジ時間 7,454 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,244 KB
testcase_01 AC 137 ms
57,372 KB
testcase_02 AC 138 ms
57,296 KB
testcase_03 AC 140 ms
57,268 KB
testcase_04 AC 137 ms
57,048 KB
testcase_05 AC 137 ms
57,236 KB
testcase_06 AC 140 ms
57,428 KB
testcase_07 AC 137 ms
57,488 KB
testcase_08 AC 139 ms
57,304 KB
testcase_09 AC 141 ms
57,368 KB
testcase_10 AC 138 ms
56,984 KB
testcase_11 AC 139 ms
57,432 KB
testcase_12 AC 141 ms
57,408 KB
testcase_13 AC 157 ms
57,688 KB
testcase_14 AC 165 ms
57,540 KB
testcase_15 AC 169 ms
55,184 KB
testcase_16 AC 139 ms
57,312 KB
testcase_17 AC 152 ms
57,352 KB
testcase_18 AC 159 ms
57,308 KB
testcase_19 AC 159 ms
57,544 KB
testcase_20 AC 159 ms
57,532 KB
testcase_21 AC 159 ms
57,276 KB
testcase_22 AC 154 ms
57,520 KB
testcase_23 AC 158 ms
57,464 KB
testcase_24 AC 157 ms
55,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] damage = new int[n];
        for (int i = 0; i < n; i++) {
            damage[i] = sc.nextInt();
        }
        int[] dp = new int[1 << n];
        dp[0] = 100;
        for (int i = 1; i < (1 << n); i++) {
            int max = 100;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) != 0 && damage[j] < 0) {
                    max += 100;
                }
            }
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                if (dp[i ^ (1 << j)] <= 0) {
                    continue;
                }
                dp[i] = Math.max(dp[i], Math.min(dp[i ^ (1 << j)] + damage[j], max));
            }
        }
        System.out.println(dp[(1 << n) - 1]);
    }
}
0