結果

問題 No.324 落ちてた閉路グラフ
ユーザー mkawa2mkawa2
提出日時 2020-02-27 08:41:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-21 16:46:45
合計ジャッジ時間 2,880 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 31 ms
10,624 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 39 ms
11,392 KB
testcase_05 AC 36 ms
11,392 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 32 ms
10,880 KB
testcase_16 RE -
testcase_17 AC 31 ms
10,496 KB
testcase_18 AC 31 ms
10,624 KB
testcase_19 AC 31 ms
10,624 KB
testcase_20 RE -
testcase_21 WA -
testcase_22 AC 31 ms
10,752 KB
testcase_23 AC 31 ms
10,624 KB
testcase_24 AC 31 ms
10,624 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 31 ms
10,752 KB
testcase_29 AC 31 ms
10,752 KB
testcase_30 AC 30 ms
10,752 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n, m = MI()
    ww = LI()
    hp = []
    for i in range(n): heappush(hp, (ww[i - 1] + ww[i], i))
    diff=n-m
    used=[False]*n
    while diff:
        s,i=heappop(hp)
        if used[i] or s!=ww[i-1]+ww[i]:continue
        used[i]=True
        ww[i-1]=ww[i]=0
        heappush(hp,(ww[i-2]+ww[i-1],i-1))
        heappush(hp,(ww[i]+ww[(i+1)%n],i))
        diff-=1
    print(sum(ww))

main()
0