結果

問題 No.1917 LCMST
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-30 10:28:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,789 ms / 4,000 ms
コード長 1,124 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 277,552 KB
最終ジャッジ日時 2023-09-12 03:06:57
合計ジャッジ時間 57,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
78,056 KB
testcase_01 AC 83 ms
77,812 KB
testcase_02 AC 89 ms
78,156 KB
testcase_03 AC 118 ms
79,776 KB
testcase_04 AC 111 ms
79,580 KB
testcase_05 AC 118 ms
80,248 KB
testcase_06 AC 115 ms
79,704 KB
testcase_07 AC 116 ms
79,812 KB
testcase_08 AC 88 ms
77,800 KB
testcase_09 AC 2,411 ms
273,828 KB
testcase_10 AC 2,359 ms
273,904 KB
testcase_11 AC 2,287 ms
272,396 KB
testcase_12 AC 1,878 ms
267,288 KB
testcase_13 AC 669 ms
246,364 KB
testcase_14 AC 2,051 ms
266,572 KB
testcase_15 AC 487 ms
246,804 KB
testcase_16 AC 719 ms
247,304 KB
testcase_17 AC 1,007 ms
248,220 KB
testcase_18 AC 1,233 ms
249,292 KB
testcase_19 AC 602 ms
247,516 KB
testcase_20 AC 468 ms
246,512 KB
testcase_21 AC 627 ms
246,388 KB
testcase_22 AC 482 ms
246,080 KB
testcase_23 AC 465 ms
247,012 KB
testcase_24 AC 619 ms
247,360 KB
testcase_25 AC 477 ms
246,660 KB
testcase_26 AC 531 ms
245,816 KB
testcase_27 AC 547 ms
247,128 KB
testcase_28 AC 571 ms
245,800 KB
testcase_29 AC 2,783 ms
276,604 KB
testcase_30 AC 2,728 ms
277,552 KB
testcase_31 AC 2,736 ms
276,736 KB
testcase_32 AC 2,766 ms
277,032 KB
testcase_33 AC 2,789 ms
276,268 KB
testcase_34 AC 269 ms
229,584 KB
testcase_35 AC 271 ms
229,164 KB
testcase_36 AC 267 ms
230,372 KB
testcase_37 AC 2,719 ms
277,384 KB
testcase_38 AC 2,694 ms
276,932 KB
testcase_39 AC 2,698 ms
276,228 KB
testcase_40 AC 2,678 ms
276,776 KB
testcase_41 AC 2,698 ms
276,968 KB
testcase_42 AC 2,599 ms
276,828 KB
testcase_43 AC 309 ms
242,320 KB
testcase_44 AC 309 ms
244,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Unionfind:
     
    def __init__(self,n):
        self.uf = [-1]*n
 
    def find(self,x):
        if self.uf[x] < 0:
            return x
        else:
            self.uf[x] = self.find(self.uf[x])
            return self.uf[x]
 
    def same(self,x,y):
        return self.find(x) == self.find(y)
 
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.uf[x] > self.uf[y]:
            x,y = y,x
        self.uf[x] += self.uf[y]
        self.uf[y] = x
        return True
 
    def size(self,x):
        x = self.find(x)
        return -self.uf[x]


n = int(input())
A = list(map(int,input().split()))
M = 10**5+5
ans = 0
count = [0]*M
for a in A:
    if count[a]:
        ans += a
    else:
        count[a] = 1


edge = []
uf = Unionfind(M)
for i in range(1,M):
    find = 0
    for j in range(i,M,i):
        if count[j] == 0:
            continue
        if find:
            edge.append([j*find//i,find,j])
        else:
            find = j

edge.sort()
for cost,x,y in edge:
    if uf.union(x,y):
        ans += cost
print(ans)
0