結果
問題 |
No.107 モンスター
|
ユーザー |
|
提出日時 | 2022-10-23 19:49:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 72 ms / 5,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 70,656 KB |
最終ジャッジ日時 | 2024-07-02 10:18:08 |
合計ジャッジ時間 | 2,303 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
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])