結果

問題 No.324 落ちてた閉路グラフ
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-18 01:24:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 9,044 KB
最終ジャッジ日時 2023-10-14 13:37:58
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,108 KB
testcase_01 AC 17 ms
8,104 KB
testcase_02 AC 17 ms
8,148 KB
testcase_03 AC 17 ms
8,220 KB
testcase_04 AC 23 ms
8,796 KB
testcase_05 AC 20 ms
9,000 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 23 ms
8,860 KB
testcase_09 AC 24 ms
8,972 KB
testcase_10 AC 23 ms
8,964 KB
testcase_11 AC 25 ms
8,840 KB
testcase_12 AC 25 ms
8,892 KB
testcase_13 AC 21 ms
8,736 KB
testcase_14 AC 17 ms
8,088 KB
testcase_15 AC 17 ms
8,168 KB
testcase_16 AC 17 ms
8,156 KB
testcase_17 AC 16 ms
8,112 KB
testcase_18 AC 17 ms
8,116 KB
testcase_19 AC 17 ms
8,100 KB
testcase_20 AC 17 ms
8,212 KB
testcase_21 AC 16 ms
8,076 KB
testcase_22 AC 17 ms
8,088 KB
testcase_23 AC 17 ms
8,080 KB
testcase_24 AC 17 ms
8,168 KB
testcase_25 WA -
testcase_26 AC 17 ms
8,108 KB
testcase_27 WA -
testcase_28 AC 17 ms
8,076 KB
testcase_29 AC 17 ms
8,088 KB
testcase_30 AC 16 ms
8,148 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def solve(n, m, ws):
    vs = [a + b for a, b in zip(ws, [ws[-1]] + ws[:-1])]
    vis = [(v, i, 2) for i, v in enumerate(vs)]
    edges = [2] * n
    e_exists = [True] * n
    v_exists = [True] * n
    vis.sort()
    cum = sum(ws)
    for _ in range(n - m):
        v, i, n_edges = heapq.heappop(vis)
        while edges[i] != n_edges or not v_exists[i]:
            v, i, n_edges = heapq.heappop(vis)
        vs[i] = 0
        cum -= v
        edges[i] = 0
        v_exists[i] = False
        j = (i + 1) % n
        k = (i - 1) % n
        if e_exists[i]:
            e_exists[i] = False
            vs[j] -= ws[i]
            ws[i] = 0
            edges[j] -= 1
            heapq.heappush(vis, (vs[j], j, edges[j]))
        if e_exists[k]:
            e_exists[k] = False
            vs[k] -= ws[k]
            ws[k] = 0
            edges[k] -= 1
            heapq.heappush(vis, (vs[k], k, edges[k]))
    return cum

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