結果

問題 No.324 落ちてた閉路グラフ
ユーザー rpy3cpprpy3cpp
提出日時 2015-12-18 00:44:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 624 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 9,048 KB
最終ジャッジ日時 2023-10-14 13:32:08
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
8,040 KB
testcase_01 AC 14 ms
8,096 KB
testcase_02 AC 14 ms
8,004 KB
testcase_03 AC 14 ms
8,040 KB
testcase_04 AC 20 ms
8,448 KB
testcase_05 AC 17 ms
8,856 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 19 ms
8,796 KB
testcase_09 AC 20 ms
8,792 KB
testcase_10 AC 19 ms
8,880 KB
testcase_11 AC 21 ms
8,784 KB
testcase_12 AC 21 ms
8,792 KB
testcase_13 AC 18 ms
8,448 KB
testcase_14 AC 15 ms
8,036 KB
testcase_15 AC 14 ms
8,188 KB
testcase_16 AC 12 ms
8,076 KB
testcase_17 AC 15 ms
8,060 KB
testcase_18 AC 14 ms
8,060 KB
testcase_19 AC 14 ms
8,072 KB
testcase_20 AC 13 ms
8,036 KB
testcase_21 AC 13 ms
8,052 KB
testcase_22 AC 13 ms
8,028 KB
testcase_23 AC 12 ms
8,060 KB
testcase_24 AC 14 ms
8,076 KB
testcase_25 WA -
testcase_26 AC 13 ms
8,032 KB
testcase_27 WA -
testcase_28 AC 14 ms
8,000 KB
testcase_29 AC 15 ms
8,080 KB
testcase_30 AC 14 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) for i, v in enumerate(vs)]
    vis.sort()
    cum = sum(ws)
    for i in range(n - m):
        v, i = heapq.heappop(vis)
        while vs[i] != v:
            v, i = heapq.heappop(vis)
        cum -= v
        vs[i] = float('inf')
        j = (i + 1) % n
        k = (i - 1) % n
        vs[j] -= ws[i]
        vs[k] -= ws[k]
        heapq.heappush(vis, (vs[j], j))
        heapq.heappush(vis, (vs[k], k))
    return cum

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