結果

問題 No.324 落ちてた閉路グラフ
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-18 22:41:38
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 1,380 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 9,156 KB
最終ジャッジ日時 2023-10-14 14:02:57
合計ジャッジ時間 15,237 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,192 KB
testcase_01 AC 14 ms
8,308 KB
testcase_02 AC 14 ms
7,752 KB
testcase_03 AC 15 ms
8,352 KB
testcase_04 AC 1,766 ms
8,404 KB
testcase_05 AC 159 ms
9,156 KB
testcase_06 AC 1,713 ms
8,456 KB
testcase_07 AC 767 ms
8,808 KB
testcase_08 AC 1,785 ms
8,532 KB
testcase_09 AC 922 ms
8,604 KB
testcase_10 AC 1,745 ms
8,592 KB
testcase_11 AC 948 ms
8,444 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 16 ms
8,252 KB
testcase_15 AC 17 ms
8,384 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 14 ms
8,284 KB
testcase_19 AC 13 ms
8,152 KB
testcase_20 RE -
testcase_21 AC 13 ms
8,200 KB
testcase_22 AC 13 ms
8,288 KB
testcase_23 AC 13 ms
8,184 KB
testcase_24 RE -
testcase_25 AC 13 ms
8,280 KB
testcase_26 AC 13 ms
8,332 KB
testcase_27 AC 14 ms
8,336 KB
testcase_28 AC 15 ms
8,348 KB
testcase_29 RE -
testcase_30 AC 13 ms
8,244 KB
testcase_31 AC 13 ms
8,136 KB
testcase_32 AC 409 ms
8,932 KB
testcase_33 AC 1,342 ms
8,812 KB
testcase_34 AC 1,325 ms
8,500 KB
testcase_35 AC 18 ms
8,272 KB
testcase_36 AC 486 ms
8,280 KB
testcase_37 AC 15 ms
8,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
ws = list(map(int, input().split()))

def solve(n, m, ws):
    f00 = [-float('inf')] * (m + 1)
    f01 = f00[:]
    f10 = f00[:]
    f11 = f00[:]
    g00 = f00[:]
    g01 = f00[:]
    g10 = f00[:]
    g11 = f00[:]
    # 初期値の設定。頂点1, 頂点2 を含むか含まないかの 4つの組み合わせに対応して初期化。
    f00[0] = 0      # 頂点1を含まない。最後尾の頂点を含まない。
    f01[1] = 0      # 頂点1を含まない。最後尾の頂点を含む。
    f10[1] = 0      # 頂点1を含む。最後尾の頂点を含まない。
    f11[2] = ws[0]  # 頂点1を含む。最後尾の頂点を含む。(最初の 2つの頂点を含むので、最初の辺を含む)
    for i, w in enumerate(ws[1:-1], 3):  # 3つ目の頂点(=2番目の辺)から順に、これを含むか否かの場合分けで計算を進めていく。
        for k in range(max(1, m + i - n), min(i, m) + 1):
            g00[k] = max(f00[k], f01[k])
            g01[k] = max(f00[k - 1], f01[k - 1] + w)
            g10[k] = max(f10[k], f11[k])
            g11[k] = max(f10[k - 1], f11[k - 1] + w)
        f00, g00 = g00, f00
        f01, g01 = g01, f01
        f10, g10 = g10, f10
        f11, g11 = g11, f11
        f00[0] = 0
    f11[m] += ws[-1]
    return max(f00[m], f01[m], f10[m], f11[m])

print(solve(n, m, ws))
0