結果

問題 No.1917 LCMST
ユーザー Koi
提出日時 2025-07-15 19:20:12
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 649 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 67,440 KB
最終ジャッジ日時 2025-07-15 19:20:20
合計ジャッジ時間 6,639 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from atcoder import dsu
M = 10 ** 5
L = [[] for _ in range(M + 1)]
for i in range(1, M + 1):
    x = i
    while x < M:
        L[x].append(i)
        x += i
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(list)
M = []
for i in range(N):
    for p in L[A[i]]:
        D[p].append((A[i], i))
for key in D.keys():
    L = D[key]
    L.sort()
    for i in range(1, len(L)):
        cost = (L[0][0] * L[i][0]) // key
        M.append((cost, L[0][1], L[i][1]))
M.sort()
ans = 0
DS = dsu.DSU(N)
for (cost, i, j) in M:
    if(not DS.same(i, j)):
        DS.merge(i, j)
        ans += cost
print(ans)
0