結果

問題 No.107 モンスター
ユーザー 👑 tipstar0125tipstar0125
提出日時 2024-01-31 15:21:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 645 ms / 5,000 ms
コード長 884 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 172,192 KB
最終ジャッジ日時 2024-01-31 15:22:06
合計ジャッジ時間 6,509 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 39 ms
53,460 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 44 ms
59,704 KB
testcase_13 AC 168 ms
97,044 KB
testcase_14 AC 297 ms
120,724 KB
testcase_15 AC 263 ms
120,724 KB
testcase_16 AC 47 ms
61,852 KB
testcase_17 AC 114 ms
85,660 KB
testcase_18 AC 645 ms
171,680 KB
testcase_19 AC 470 ms
171,808 KB
testcase_20 AC 168 ms
96,788 KB
testcase_21 AC 163 ms
96,788 KB
testcase_22 AC 305 ms
121,364 KB
testcase_23 AC 580 ms
171,680 KB
testcase_24 AC 551 ms
172,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
D=list(map(int,input().split()))
MAX=1<<N
dp=[[[0,100] for _ in range(N)] for _ in range(MAX)]
for i in range(N):
    if D[i]<0:dp[1<<i][i]=[100+D[i],200]
    else:dp[1<<i][i]=[100,100]

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]<=0:continue
            if D[to]<0:
                if dp[bs][frm][0]+D[to]>dp[s][to][0]:
                    dp[s][to][0]=dp[bs][frm][0]+D[to]
                    dp[s][to][1]=dp[bs][frm][1]+100
            else:
                mx=dp[bs][frm][1]
                if min(mx,dp[bs][frm][0]+D[to])>dp[s][to][0]:
                    dp[s][to][0]=min(mx,dp[bs][frm][0]+D[to])
                    dp[s][to][1]=dp[bs][frm][1]
ans=0
for i in range(N):ans=max(ans,dp[-1][i][0])
print(ans)
0