結果

問題 No.107 モンスター
ユーザー takeya_okinotakeya_okino
提出日時 2019-07-26 23:33:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 1,182 bytes
コンパイル時間 4,029 ms
コンパイル使用メモリ 73,544 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-09-15 05:01:35
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,784 KB
testcase_01 AC 124 ms
55,760 KB
testcase_02 AC 122 ms
56,216 KB
testcase_03 AC 124 ms
55,832 KB
testcase_04 AC 127 ms
55,456 KB
testcase_05 AC 124 ms
55,696 KB
testcase_06 AC 122 ms
55,620 KB
testcase_07 AC 121 ms
55,456 KB
testcase_08 AC 124 ms
56,008 KB
testcase_09 AC 121 ms
55,752 KB
testcase_10 AC 121 ms
55,788 KB
testcase_11 AC 122 ms
56,004 KB
testcase_12 AC 124 ms
55,744 KB
testcase_13 AC 135 ms
55,712 KB
testcase_14 AC 161 ms
55,832 KB
testcase_15 AC 155 ms
55,664 KB
testcase_16 AC 124 ms
56,032 KB
testcase_17 AC 135 ms
56,464 KB
testcase_18 AC 154 ms
55,704 KB
testcase_19 AC 152 ms
55,476 KB
testcase_20 AC 137 ms
55,836 KB
testcase_21 AC 138 ms
55,748 KB
testcase_22 AC 150 ms
55,704 KB
testcase_23 AC 158 ms
55,820 KB
testcase_24 AC 158 ms
55,644 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[] d = new int[n];
    for(int i = 0; i < n; i++) {
      d[i] = sc.nextInt();
    }
    int p = (int)Math.pow(2, n);
    int[] kosuu = new int[p];
    int[] dp = new int[p];
    for(int i = 1; i < p; i++) {
      for(int j = 0; j < n; j++) {
        if(((i & (1 << j)) != 0) && (d[j] < 0)) kosuu[i]++;
      }
    }
    for(int i = 0; i < p; i++) {
      dp[i] = -1;
    }
    dp[0] = 100;
    for(int i = 1; i < p; i++) {
      for(int j = 0; j < n; j++) {
        if((i & (1 << j)) != 0) {
          int i1 = i - (1 << j);
          if(dp[i1] > 0) {
            int t = dp[i1];
            int max = 100 + kosuu[i1] * 100;
            if(d[j] > 0) {
              t = Math.min(t + d[j], max);
            } else {
              if((t + d[j]) > 0) {
                t += d[j];
              } else {
                t = -1;
              }
            }
            dp[i] = Math.max(dp[i], t);
          }
        }
      }
    }
    int ans = dp[p - 1];
    if(dp[p - 1] == -1) ans = 0;
    System.out.println(ans);
  }
}
0