結果

問題 No.1917 LCMST
ユーザー ああいいああいい
提出日時 2022-04-29 22:58:06
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 894 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 849,592 KB
最終ジャッジ日時 2023-09-11 14:23:55
合計ジャッジ時間 19,006 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
76,324 KB
testcase_01 AC 67 ms
76,416 KB
testcase_02 AC 66 ms
76,376 KB
testcase_03 AC 2,389 ms
272,088 KB
testcase_04 AC 2,167 ms
270,968 KB
testcase_05 AC 2,160 ms
269,428 KB
testcase_06 AC 2,183 ms
271,064 KB
testcase_07 AC 2,340 ms
272,484 KB
testcase_08 AC 68 ms
76,388 KB
testcase_09 MLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
A.sort()
C = 10 ** 5 + 1
dat = [0] * C

parent = list(range(N))
import sys
sys.setrecursionlimit(10 ** 8)
def find(i):
    if parent[i] == i:
        return i
    parent[i] = find(parent[i])
    return parent[i]
def unit(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[I] = J
    parent[i] = J
    return True
def isSame(i,j):
    return find(i) == find(j)

def lcm(a,b):
    x,y = a,b
    while True:
        r = a % b
        a = b
        b = r
        if r == 0:
            return x // a * y

l = []
for i in range(N):
    a = A[i]
    if dat[a] > 0:continue
    for j in range(a,C,a):
        dat[j] = 1
    for j in range(N):
        if j != i:
            l.append((lcm(a,A[j]),i,j))
l.sort(key = lambda x:x[0])
ans = 0
for t,i,j in l:
    if not isSame(i,j):
        ans += t
        unit(i,j)
print(ans)
0