結果

問題 No.107 モンスター
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-03-04 01:00:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 5,000 ms
コード長 778 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 81,576 KB
実行使用メモリ 77,096 KB
最終ジャッジ日時 2023-10-18 04:03:43
合計ジャッジ時間 4,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,604 KB
testcase_01 AC 48 ms
55,604 KB
testcase_02 AC 45 ms
55,604 KB
testcase_03 AC 46 ms
55,604 KB
testcase_04 AC 46 ms
55,604 KB
testcase_05 AC 44 ms
55,604 KB
testcase_06 AC 44 ms
55,604 KB
testcase_07 AC 44 ms
55,604 KB
testcase_08 AC 44 ms
55,604 KB
testcase_09 AC 44 ms
55,604 KB
testcase_10 AC 44 ms
55,604 KB
testcase_11 AC 45 ms
55,604 KB
testcase_12 AC 45 ms
55,604 KB
testcase_13 AC 91 ms
76,484 KB
testcase_14 AC 81 ms
76,584 KB
testcase_15 AC 81 ms
76,588 KB
testcase_16 AC 45 ms
55,604 KB
testcase_17 AC 85 ms
76,584 KB
testcase_18 AC 82 ms
76,992 KB
testcase_19 AC 75 ms
74,876 KB
testcase_20 AC 80 ms
76,476 KB
testcase_21 AC 86 ms
76,532 KB
testcase_22 AC 109 ms
76,676 KB
testcase_23 AC 92 ms
76,920 KB
testcase_24 AC 102 ms
77,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
import sys,math
input = sys.stdin.readline

N = int(input())
D = list(map(int,input().split()))
msk0 = 0
msk1 = 0
for i,d in enumerate(D):
    if d<0:
        msk0 += (1<<i)
    else:
        msk1 += (1<<i)
    
INF = (1<<60)

dp = [-1]*(1<<N)
dp[0] = 100

for i in range(1<<N):
    
    if dp[i]<=0:
        continue
    
    cnd = []
    for j in range(N):
        if (i>>j)&1:
            continue
        cnd.append(j)
    
    for c in cnd:
        
        if (1<<c)&msk0:
            
            dp[i|(1<<c)] = max(dp[i|(1<<c)],dp[i] + D[c])
            
        else:
            
            dp[i|(1<<c)] = max(dp[i|(1<<c)],min(dp[i]+D[c],100*(bin(i&msk0).count('1') + 1)))
print(max(dp[-1],0))
0