結果

問題 No.107 モンスター
ユーザー tipstar0125
提出日時 2024-01-31 15:36:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 328 ms / 5,000 ms
コード長 639 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 89,600 KB
最終ジャッジ日時 2024-09-28 10:22:54
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
D=list(map(int,input().split()))
MAX=1<<N
dp=[[0 for _ in range(N)] for _ in range(MAX)]
for i in range(N):dp[1<<i][i]=max(0,min(100,100+D[i]))
for s in range(1,MAX):
    for frm in range(N):
        if s&(1<<frm)==0:continue
        for to in range(N):
            if s&(1<<to)==0:continue
            bs=s^(1<<to)
            if dp[bs][frm]==0:continue
            level=1
            for i in range(N):
                if bs&(1<<i)>0 and D[i]<0:level+=1
            if D[to]<0:dp[s][to]=max(dp[s][to],dp[bs][frm]+D[to])
            else:dp[s][to]=max(dp[s][to],min(level*100,dp[bs][frm]+D[to]))
ans=max(dp[-1])
print(ans)
0