結果

問題 No.107 モンスター
ユーザー tobusakanatobusakana
提出日時 2022-10-23 19:49:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 981 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 77,308 KB
最終ジャッジ日時 2023-09-15 05:20:26
合計ジャッジ時間 3,545 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,444 KB
testcase_01 AC 73 ms
71,304 KB
testcase_02 AC 71 ms
71,592 KB
testcase_03 AC 70 ms
71,428 KB
testcase_04 AC 70 ms
71,572 KB
testcase_05 AC 73 ms
71,372 KB
testcase_06 AC 70 ms
71,368 KB
testcase_07 AC 73 ms
71,396 KB
testcase_08 AC 72 ms
71,284 KB
testcase_09 AC 73 ms
71,596 KB
testcase_10 AC 71 ms
71,396 KB
testcase_11 AC 72 ms
71,340 KB
testcase_12 AC 72 ms
71,368 KB
testcase_13 AC 92 ms
76,840 KB
testcase_14 AC 96 ms
77,012 KB
testcase_15 AC 96 ms
76,736 KB
testcase_16 AC 72 ms
71,284 KB
testcase_17 AC 99 ms
76,472 KB
testcase_18 AC 95 ms
77,192 KB
testcase_19 AC 93 ms
77,140 KB
testcase_20 AC 98 ms
76,704 KB
testcase_21 AC 99 ms
76,888 KB
testcase_22 AC 103 ms
77,152 KB
testcase_23 AC 104 ms
77,308 KB
testcase_24 AC 102 ms
77,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N = int(readline())
D = list(map(int,readline().split()))

# dp[S] = 今までに出会ったモンスターの集合Sに対する、最大の体力
# 回復の最大値はSの情報からわかる

dp = [0] * (1 << N)
dp[0] = 100
for status in range(1 << N):
  if dp[status] == 0: # 0の場合は次の行動が出来ない。
    continue
  # 現在の状態での最大体力を求める。
  level_up = 0
  for i in range(N):
    if D[i] < 0 and (status >> i) & 1: # 悪いモンスターを倒した
      level_up += 1
  max_hp = 100 * (level_up + 1)
  # 次に出会うモンスターを全探索
  for target in range(N):
    if (status >> target) & 1:
      continue
    next_status = status | (1 << target)
    if D[target] > 0: # 良いモンスター
      hp = min(max_hp, dp[status] + D[target])
    else:
      hp = max(0, dp[status] + D[target])
    if dp[next_status] < hp:
      dp[next_status] = hp
      
print(dp[-1])
0