結果

問題 No.324 落ちてた閉路グラフ
ユーザー H3PO4H3PO4
提出日時 2020-10-19 08:54:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 211 ms / 5,000 ms
コード長 891 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 30,384 KB
最終ジャッジ日時 2023-09-28 13:11:20
合計ジャッジ時間 7,925 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
29,732 KB
testcase_01 AC 136 ms
29,768 KB
testcase_02 AC 138 ms
29,640 KB
testcase_03 AC 136 ms
29,728 KB
testcase_04 AC 202 ms
29,804 KB
testcase_05 AC 211 ms
30,384 KB
testcase_06 AC 190 ms
29,988 KB
testcase_07 AC 206 ms
30,140 KB
testcase_08 AC 190 ms
30,024 KB
testcase_09 AC 179 ms
30,068 KB
testcase_10 AC 191 ms
29,996 KB
testcase_11 AC 187 ms
30,032 KB
testcase_12 AC 140 ms
29,892 KB
testcase_13 AC 136 ms
29,816 KB
testcase_14 AC 155 ms
29,832 KB
testcase_15 AC 169 ms
29,892 KB
testcase_16 AC 146 ms
29,628 KB
testcase_17 AC 138 ms
29,544 KB
testcase_18 AC 138 ms
29,788 KB
testcase_19 AC 135 ms
29,784 KB
testcase_20 AC 136 ms
29,512 KB
testcase_21 AC 136 ms
29,644 KB
testcase_22 AC 137 ms
29,776 KB
testcase_23 AC 138 ms
29,728 KB
testcase_24 AC 136 ms
29,588 KB
testcase_25 AC 134 ms
29,692 KB
testcase_26 AC 137 ms
29,696 KB
testcase_27 AC 138 ms
29,748 KB
testcase_28 AC 137 ms
29,676 KB
testcase_29 AC 138 ms
29,532 KB
testcase_30 AC 137 ms
29,828 KB
testcase_31 AC 134 ms
29,672 KB
testcase_32 AC 211 ms
30,180 KB
testcase_33 AC 206 ms
30,032 KB
testcase_34 AC 188 ms
30,152 KB
testcase_35 AC 144 ms
29,740 KB
testcase_36 AC 178 ms
29,928 KB
testcase_37 AC 142 ms
29,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, M = map(int, input().split())
W = tuple(map(int, input().split()))
MAX = 1_000_000

if M < 2:
    print(0)
    exit()


def dp(last, non_last):
    for w in W[:-1]:
        new_last = np.full(M + 1, -MAX)
        new_last[1:] = np.maximum(last[:-1] + w, non_last[:-1])
        new_non_last = np.maximum(last, non_last)
        last, non_last = new_last, new_non_last
    return last, non_last


# dp[i] = iコの点を打ち終えている
# 一番目の点を含む
dp_last = np.full(M + 1, -MAX)
dp_non_last = np.full(M + 1, -MAX)
dp_last[1] = 0
dp_last, dp_non_last = dp(dp_last, dp_non_last)
ans = max(dp_last[-1] + W[-1], dp_non_last[-1])

# 一番目の点を含まない

dp_last = np.full(M + 1, -MAX)
dp_non_last = np.full(M + 1, -MAX)
dp_non_last[0] = 0
dp_last, dp_non_last = dp(dp_last, dp_non_last)
ans = max(ans, dp_last[-1], dp_non_last[-1])
print(ans)
0