結果

問題 No.107 モンスター
コンテスト
ユーザー maspy
提出日時 2020-03-05 15:29:42
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 702 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,165 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 68,992 KB
最終ジャッジ日時 2026-05-01 11:44:10
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
N, *D = map(int, read().split())

# %%
HP_limit = [100]
for x in D:
    if x > 0:
        HP_limit += HP_limit
    else:
        HP_limit += [y + 100 for y in HP_limit]


# %%
dp = [0] * (1 << N)
dp[0] = 100
for n in range(1 << N):
    for i, d in enumerate(D):
        if n & (1 << i):
            continue
        if not dp[n]:
            continue
        m = n ^ (1 << i)
        if d > 0:
            x = min(dp[n] + d, HP_limit[n])
        else:
            x = dp[n] + d
        if dp[m] < x:
            dp[m] = x


# %%
print(max(0, dp[-1]))
0