結果

問題 No.107 モンスター
ユーザー tcltktcltk
提出日時 2021-05-18 04:34:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 90,792 KB
最終ジャッジ日時 2024-04-16 18:59:26
合計ジャッジ時間 5,294 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
86,912 KB
testcase_01 AC 126 ms
86,876 KB
testcase_02 AC 130 ms
86,740 KB
testcase_03 AC 125 ms
86,912 KB
testcase_04 AC 126 ms
86,872 KB
testcase_05 AC 123 ms
86,912 KB
testcase_06 AC 126 ms
87,040 KB
testcase_07 AC 126 ms
86,912 KB
testcase_08 AC 124 ms
86,928 KB
testcase_09 AC 126 ms
86,528 KB
testcase_10 AC 128 ms
86,528 KB
testcase_11 AC 125 ms
86,784 KB
testcase_12 AC 129 ms
86,956 KB
testcase_13 AC 199 ms
89,856 KB
testcase_14 AC 190 ms
90,368 KB
testcase_15 AC 187 ms
90,108 KB
testcase_16 AC 124 ms
86,668 KB
testcase_17 AC 185 ms
89,984 KB
testcase_18 AC 185 ms
90,660 KB
testcase_19 AC 191 ms
90,496 KB
testcase_20 AC 202 ms
90,296 KB
testcase_21 AC 229 ms
90,240 KB
testcase_22 AC 236 ms
90,276 KB
testcase_23 AC 208 ms
90,776 KB
testcase_24 AC 220 ms
90,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N = int(input())
    D = list(map(int, input().split()))

    dp = [0] * (1<<N)
    dp[0] = 100
    for s in range(1<<N):
        if dp[s] == 0:
            continue
        for i in range(N):
            if s & (1<<i):
                continue
            s1 = s | (1<<i)
            if D[i] > 0:
                max_hp = 100 + sum(100 for j in range(N) if D[j] < 0 and s & (1<<j))
                hp1 = min(dp[s] + D[i], max_hp)
                dp[s1] = max(dp[s1], hp1)
            else:
                hp1 = dp[s] + D[i]
                if hp1 > 0:
                    dp[s1] = max(dp[s1], hp1)
    ans = dp[(1<<N)-1]
    print(ans)

if __name__ == '__main__':
    main()
0