結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
みあえ
|
| 提出日時 | 2024-04-05 06:40:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 605 ms / 5,000 ms |
| コード長 | 792 bytes |
| コンパイル時間 | 355 ms |
| コンパイル使用メモリ | 82,252 KB |
| 実行使用メモリ | 77,356 KB |
| 最終ジャッジ日時 | 2024-10-01 00:57:08 |
| 合計ジャッジ時間 | 5,838 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
def solve(N, A):
dp = [-float("inf")] * (1 << N)
dp[0] = 100
for V in range(1 << N):
for i, a in enumerate(A):
if (V >> i) & 1:
continue
max_hp = 100
for j, b in enumerate(f"{V:0{N}b}"[::-1]):
if b == "1" and A[j] < 0:
max_hp += 100
VV = V | (1 << i)
if a > 0:
hp = min(max_hp, dp[V] + a)
else:
hp = max(0, dp[V] + a)
if hp == 0:
hp = -float("inf")
dp[VV] = max(dp[VV], hp)
ans = max(0, dp[-1])
return ans
def main():
N = int(input())
A = list(map(int, input().split()))
ans = solve(N, A)
print(ans)
if __name__ == "__main__":
main()
みあえ