結果

問題 No.107 モンスター
ユーザー ぴろずぴろず
提出日時 2014-12-18 23:46:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 851 bytes
コンパイル時間 2,796 ms
コンパイル使用メモリ 78,616 KB
実行使用メモリ 55,920 KB
最終ジャッジ日時 2023-08-22 22:22:23
合計ジャッジ時間 7,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,684 KB
testcase_01 AC 127 ms
55,768 KB
testcase_02 AC 129 ms
55,816 KB
testcase_03 AC 125 ms
55,716 KB
testcase_04 AC 126 ms
55,856 KB
testcase_05 AC 125 ms
55,748 KB
testcase_06 AC 126 ms
55,876 KB
testcase_07 AC 126 ms
55,700 KB
testcase_08 AC 125 ms
55,508 KB
testcase_09 AC 126 ms
55,516 KB
testcase_10 AC 125 ms
55,792 KB
testcase_11 AC 127 ms
55,864 KB
testcase_12 AC 127 ms
55,680 KB
testcase_13 AC 143 ms
55,812 KB
testcase_14 AC 148 ms
55,788 KB
testcase_15 AC 151 ms
55,660 KB
testcase_16 AC 128 ms
55,652 KB
testcase_17 AC 135 ms
55,452 KB
testcase_18 AC 148 ms
55,672 KB
testcase_19 AC 148 ms
55,592 KB
testcase_20 AC 146 ms
55,812 KB
testcase_21 AC 145 ms
55,556 KB
testcase_22 AC 142 ms
55,920 KB
testcase_23 AC 147 ms
55,896 KB
testcase_24 AC 148 ms
55,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no107;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0;i<n;i++) {
			d[i] = sc.nextInt();
		}
		int[] dp = new int[1<<n];
		Arrays.fill(dp, -(1<<29));
		dp[0] = 100;
		for(int i=0;i<(1<<n);i++) {
			int maxhp = 100;
			for(int j=0;j<n;j++) {
				if ((i>>j & 1) > 0 && d[j] < 0) {
					maxhp += 100;
				}
			}
			for(int j=0;j<n;j++) {
				if ((i>>j & 1) > 0) {
					int k = i ^ 1<<j;
					if (d[j] < 0) {
						dp[i] = Math.max(dp[i], dp[k] + d[j]);
					}else{
						dp[i] = Math.max(dp[i], Math.min(dp[k] + d[j], maxhp));
					}
					if (dp[i] <= 0) {
						dp[i] = -(1<<29);
					}
				}
			}
		}
		int ans = dp[(1<<n)-1];
		System.out.println(ans < 0 ? 0 : ans);
	}

}
0