結果

問題 No.107 モンスター
ユーザー te-shte-sh
提出日時 2016-09-06 11:40:37
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 936 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 104,768 KB
実行使用メモリ 4,492 KB
最終ジャッジ日時 2023-09-02 21:56:22
合計ジャッジ時間 2,085 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 4 ms
4,372 KB
testcase_14 AC 6 ms
4,368 KB
testcase_15 AC 7 ms
4,372 KB
testcase_16 AC 1 ms
4,372 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 7 ms
4,372 KB
testcase_19 AC 7 ms
4,492 KB
testcase_20 AC 5 ms
4,368 KB
testcase_21 AC 4 ms
4,372 KB
testcase_22 AC 6 ms
4,372 KB
testcase_23 AC 10 ms
4,368 KB
testcase_24 AC 9 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!int;
  auto di = readln.split.map!(to!int);

  auto b = 0;
  foreach (i; 0..n)
    if (di[i] < 0) b |= (1 << i);

  int calcMaxHp(int i) {
    return 100 + (b & i).popcnt * 100;
  }

  int calcHp(int hp, int i, int j) {
    auto d = di[j];
    if (d > 0) {
      return min(calcMaxHp(i), hp + d);
    } else
      return max(0, hp + d);
  }

  auto memo = new int[](1 << n);
  memo[0] = 100;

  foreach (i; 1..1 << n) {
    auto maxHp = 0;
    foreach (j; 0..n) {
      if (i & (1 << j)) {
        auto k = i ^ (1 << j);
        if (memo[k] > 0) {
          auto hp = calcHp(memo[k], k, j);
          maxHp = max(maxHp, hp);
        }
      }
    }
    memo[i] = maxHp;
  }

  writeln(memo[$ - 1]);
}
0