結果

問題 No.107 モンスター
ユーザー UekiUeki
提出日時 2019-05-16 12:06:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,040 ms / 5,000 ms
コード長 1,291 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2023-10-17 06:49:27
合計ジャッジ時間 11,372 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,184 KB
testcase_01 AC 28 ms
10,184 KB
testcase_02 AC 28 ms
10,184 KB
testcase_03 AC 28 ms
10,184 KB
testcase_04 AC 28 ms
10,184 KB
testcase_05 AC 28 ms
10,184 KB
testcase_06 AC 29 ms
10,184 KB
testcase_07 AC 28 ms
10,184 KB
testcase_08 AC 28 ms
10,184 KB
testcase_09 AC 28 ms
10,184 KB
testcase_10 AC 29 ms
10,184 KB
testcase_11 AC 28 ms
10,184 KB
testcase_12 AC 28 ms
10,184 KB
testcase_13 AC 490 ms
10,248 KB
testcase_14 AC 378 ms
10,492 KB
testcase_15 AC 382 ms
10,492 KB
testcase_16 AC 29 ms
10,184 KB
testcase_17 AC 195 ms
10,280 KB
testcase_18 AC 1,655 ms
10,492 KB
testcase_19 AC 1,646 ms
10,492 KB
testcase_20 AC 193 ms
10,492 KB
testcase_21 AC 258 ms
10,312 KB
testcase_22 AC 920 ms
10,492 KB
testcase_23 AC 1,089 ms
10,756 KB
testcase_24 AC 2,040 ms
10,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
mosters = list(map(int, input().split()))
# max,current
dp = [-float('inf')]*(1 << N)
dp[0] = 100

for mask in range(1 << N):
    for new_moster in range(N):
        # もう倒していたらpass
        if mask >> new_moster & 1:
            continue
        new_state = mask | 1 << new_moster

        if mosters[new_moster] > 0:  # kind moster
            # print("kind")
            current_maxHP = 100
            for m in range(N):
                if mask >> m & 1 == 1 or m == new_moster:
                    # 今までに倒したevil mosterだけmaxHPが上がっている
                    if mosters[m] < 0:
                        current_maxHP += 100
            dp[new_state] = max(dp[new_state],
                                min(dp[mask]+mosters[new_moster], current_maxHP))

        else:  # evil moster
            nextHP = dp[mask]+mosters[new_moster]
            if nextHP <= 0:
                # print("end")
                dp[new_state] = max(dp[new_state], -float('inf'))
            else:
                dp[new_state] = max(dp[new_state], nextHP)
ans = dp[-1]
if ans == -float('inf'):
    print(0)
else:
    print(ans)
0