結果

問題 No.107 モンスター
ユーザー te-shte-sh
提出日時 2017-01-27 17:42:05
言語 D
(dmd 2.105.2)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,006 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 87,896 KB
実行使用メモリ 47,032 KB
最終ジャッジ日時 2023-09-03 00:59:16
合計ジャッジ時間 4,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 RE -
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 21 ms
8,108 KB
testcase_14 AC 79 ms
18,128 KB
testcase_15 AC 79 ms
16,352 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 17 ms
6,972 KB
testcase_18 AC 22 ms
17,168 KB
testcase_19 AC 23 ms
18,172 KB
testcase_20 AC 526 ms
47,032 KB
testcase_21 AC 182 ms
26,516 KB
testcase_22 AC 431 ms
43,880 KB
testcase_23 AC 283 ms
46,760 KB
testcase_24 AC 218 ms
36,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

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

  auto dp = new int[int][][](1 << n, n + 1);

  int calc(int s, int lv, int hp) {
    if (hp in dp[s][lv]) {
      return dp[s][lv][hp];
    } else if (s == 0) {
      return dp[s][lv][hp] = hp;
    } else {
      auto maxHp = 0;
      foreach (j; 0..n) {
        if (bitTest(s, j)) {
          auto ns = bitReset(s, j);
          auto nhp = 0;
          if (di[j] > 0) {
            nhp = calc(ns, lv, min(hp + di[j], lv * 100));
          } else {
            if (hp <= -di[j])
              nhp = 0;
            else
              nhp = calc(ns, lv + 1, hp + di[j]);
          }
          maxHp = max(maxHp, nhp);
        }
      }
      return dp[s][lv][hp] = maxHp;
    }
  }

  writeln(calc((1 << n) - 1, 1, 100));
}

bool bitTest(T)(T n, size_t i) { return (n & (1.to!T << i)) != 0; }
T bitReset(T)(T n, size_t i) { return n & ~(1.to!T << i); }
0