結果

問題 No.107 モンスター
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-29 13:44:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 626 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 77,792 KB
最終ジャッジ日時 2023-09-23 10:40:59
合計ジャッジ時間 4,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,460 KB
testcase_01 AC 72 ms
71,360 KB
testcase_02 AC 71 ms
71,520 KB
testcase_03 AC 72 ms
71,548 KB
testcase_04 AC 73 ms
71,260 KB
testcase_05 AC 72 ms
71,360 KB
testcase_06 AC 73 ms
71,112 KB
testcase_07 AC 72 ms
71,340 KB
testcase_08 AC 71 ms
71,252 KB
testcase_09 AC 74 ms
71,596 KB
testcase_10 AC 71 ms
71,248 KB
testcase_11 AC 73 ms
71,368 KB
testcase_12 AC 72 ms
71,492 KB
testcase_13 AC 104 ms
76,852 KB
testcase_14 AC 109 ms
76,864 KB
testcase_15 AC 106 ms
76,732 KB
testcase_16 AC 74 ms
71,344 KB
testcase_17 AC 98 ms
76,704 KB
testcase_18 AC 120 ms
77,792 KB
testcase_19 AC 115 ms
77,644 KB
testcase_20 AC 95 ms
76,704 KB
testcase_21 AC 99 ms
76,492 KB
testcase_22 AC 108 ms
77,160 KB
testcase_23 AC 121 ms
77,672 KB
testcase_24 AC 118 ms
77,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
D = list(map(int, input().split()))
bad = set()
for i, d in enumerate(D):
    if d < 0:
        bad.add(i)
INF = 10**18
dp = [-INF]*(1<<n)
dp[0] = 100
for s in range(1<<n):
    maxh = 100
    for i in bad:
        if (s>>i)&1:
            maxh += 100
    for i in range(n):
        if (s>>i) & 1:
            continue
        ns = s|(1<<i)
        if D[i] >= 0:
            dp[ns] = max(dp[ns], min(maxh, dp[s]+D[i]))
        else:
            if dp[s]+D[i] <= 0:
                continue
            else:
                dp[ns] = max(dp[ns], dp[s]+D[i])
if dp[-1] <= 0:
    print(0)
else:
    print(dp[-1])
0