結果

問題 No.324 落ちてた閉路グラフ
ユーザー rlangevinrlangevin
提出日時 2023-08-24 12:42:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,318 ms / 5,000 ms
コード長 793 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 126,380 KB
最終ジャッジ日時 2023-08-24 12:42:44
合計ジャッジ時間 20,270 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,268 KB
testcase_01 AC 79 ms
71,264 KB
testcase_02 AC 70 ms
71,220 KB
testcase_03 AC 78 ms
71,564 KB
testcase_04 AC 943 ms
121,160 KB
testcase_05 AC 1,031 ms
120,608 KB
testcase_06 AC 1,193 ms
117,788 KB
testcase_07 AC 1,178 ms
119,312 KB
testcase_08 AC 1,284 ms
124,732 KB
testcase_09 AC 1,309 ms
122,448 KB
testcase_10 AC 1,165 ms
126,380 KB
testcase_11 AC 1,305 ms
125,280 KB
testcase_12 AC 1,100 ms
120,572 KB
testcase_13 AC 503 ms
87,988 KB
testcase_14 AC 217 ms
79,236 KB
testcase_15 AC 299 ms
81,792 KB
testcase_16 AC 72 ms
71,568 KB
testcase_17 AC 78 ms
71,304 KB
testcase_18 AC 73 ms
71,564 KB
testcase_19 AC 73 ms
71,168 KB
testcase_20 AC 72 ms
71,632 KB
testcase_21 AC 76 ms
71,544 KB
testcase_22 AC 76 ms
71,364 KB
testcase_23 AC 74 ms
71,376 KB
testcase_24 AC 73 ms
71,232 KB
testcase_25 AC 73 ms
71,300 KB
testcase_26 AC 74 ms
71,372 KB
testcase_27 AC 72 ms
71,600 KB
testcase_28 AC 73 ms
71,360 KB
testcase_29 AC 77 ms
71,308 KB
testcase_30 AC 74 ms
71,464 KB
testcase_31 AC 73 ms
71,216 KB
testcase_32 AC 1,288 ms
121,736 KB
testcase_33 AC 1,318 ms
123,112 KB
testcase_34 AC 943 ms
107,364 KB
testcase_35 AC 110 ms
77,592 KB
testcase_36 AC 778 ms
94,680 KB
testcase_37 AC 115 ms
77,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
W = list(map(int, input().split()))
inf = 10 ** 18
pre = [[-inf] * 2 for i in range(N + 1)]
pre[0][0] = 0
for i in range(1, N):
    dp = [[-inf] * 2 for i in range(N + 1)]
    for j in range(N + 1):
        dp[j][0] = max(dp[j][0], pre[j][0], pre[j][1])
        if j:
            dp[j][1] = max(dp[j][1], pre[j - 1][1] + W[i - 1], pre[j - 1][0])
    dp, pre = pre, dp
ans = max(pre[M])

pre = [[-inf] * 2 for i in range(N + 1)]
pre[1][1] = 0
for i in range(1, N):
    dp = [[-inf] * 2 for i in range(N + 1)]
    for j in range(N + 1):
        dp[j][0] = max(dp[j][0], pre[j][0], pre[j][1])
        if j:
            dp[j][1] = max(dp[j][1], pre[j - 1][1] + W[i - 1], pre[j - 1][0])
    dp, pre = pre, dp

ans = max(ans, pre[M][0], pre[M][1] + W[-1])
print(ans)
0