結果

問題 No.107 モンスター
ユーザー GrenacheGrenache
提出日時 2016-05-26 23:26:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 148 ms / 5,000 ms
コード長 1,098 bytes
コンパイル時間 4,576 ms
コンパイル使用メモリ 74,248 KB
実行使用メモリ 60,832 KB
最終ジャッジ日時 2023-08-23 06:54:09
合計ジャッジ時間 9,166 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,640 KB
testcase_01 AC 124 ms
55,476 KB
testcase_02 AC 124 ms
55,704 KB
testcase_03 AC 125 ms
55,796 KB
testcase_04 AC 124 ms
55,880 KB
testcase_05 AC 125 ms
56,056 KB
testcase_06 AC 126 ms
55,836 KB
testcase_07 AC 122 ms
56,000 KB
testcase_08 AC 123 ms
55,900 KB
testcase_09 AC 124 ms
56,348 KB
testcase_10 AC 125 ms
55,732 KB
testcase_11 AC 125 ms
56,256 KB
testcase_12 AC 125 ms
56,064 KB
testcase_13 AC 137 ms
55,948 KB
testcase_14 AC 148 ms
58,096 KB
testcase_15 AC 147 ms
58,456 KB
testcase_16 AC 122 ms
55,668 KB
testcase_17 AC 141 ms
56,096 KB
testcase_18 AC 140 ms
60,316 KB
testcase_19 AC 139 ms
60,356 KB
testcase_20 AC 138 ms
56,428 KB
testcase_21 AC 145 ms
56,128 KB
testcase_22 AC 140 ms
58,076 KB
testcase_23 AC 142 ms
60,832 KB
testcase_24 AC 143 ms
60,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder107 {

    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[n + 1][0x1 << n];
        dp[0][0] = 100;
        for (int i = 0; i < 0x1 << n; i++) {
        	for (int k = 0; k < n; k++) {
        		if (dp[k][i] == 0) {
        			continue;
        		}

        		for (int j = 0; j < n; j++) {
        			if ((i & 0x1 << j) != 0) {
        				continue;
        			}

        			if (d[j] < 0) {
        				dp[k + 1][i | 0x1 << j] = Math.max(dp[k + 1][i | 0x1 << j], dp[k][i] + d[j]);
        			} else {
        				dp[k][i | 0x1 << j] = Math.max(dp[k][i | 0x1 << j], Math.min(100 * (k + 1), dp[k][i] + d[j]));
        			}
        		}
        	}
        }

        int max = 0;
        for (int i = 0; i <= n; i++) {
        	max = Math.max(max, dp[i][(0x1 << n) - 1]);
        }

    	System.out.println(max);

    	sc.close();
    }
}
0