結果
| 問題 | No.1917 LCMST |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-24 18:26:05 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 954 bytes |
| 記録 | |
| コンパイル時間 | 322 ms |
| コンパイル使用メモリ | 85,268 KB |
| 実行使用メモリ | 227,364 KB |
| 最終ジャッジ日時 | 2026-05-24 18:26:39 |
| 合計ジャッジ時間 | 28,888 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 33 |
ソースコード
import heapq
def aa(m):
c=[]
while m!=uf[m]:
c.append(m)
m=uf[m]
for i in c:
uf[i]=m
return m
n=int(input())
a=list(map(int,input().split()))
x=[0]*(10**5+1)
for i in a:
x[i]+=1
v=[];ans=0
c=[[] for i in range(len(x))]
d=[1<<60]*len(x)
f=[0]*len(x)
uf=[i for i in range(len(x))]
for i in range(len(x)):
if x[i]:
ans+=(x[i]-1)*i
for j in range(1,int(i**0.5)+1):
if i%j==0:
heapq.heappush(c[j],(i//j,i))
if j!=i//j:
heapq.heappush(c[i//j],(j,i))
for i in range(len(x)):
if len(c[i])>=2:
q,w=heapq.heappop(c[i])
d[i]=q*i;f[i]=w
q,w=heapq.heappop(c[i])
heapq.heappush(v,(d[i]*q,i,w))
while v:
q,w,e=heapq.heappop(v)
if aa(e)==aa(f[w]):
continue
ans+=q
uf[aa(e)]=aa(f[w])
if c[w]:
a,b=heapq.heappop(c[w])
heapq.heappush(v,(d[w]*a,w,b))
print(ans)