結果

問題 No.1917 LCMST
ユーザー ああいいああいい
提出日時 2022-04-29 23:35:07
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 962 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 843,976 KB
最終ジャッジ日時 2023-09-11 15:14:25
合計ジャッジ時間 14,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,212 KB
testcase_01 AC 76 ms
76,468 KB
testcase_02 AC 73 ms
76,440 KB
testcase_03 AC 1,101 ms
169,508 KB
testcase_04 AC 1,087 ms
166,688 KB
testcase_05 AC 1,080 ms
166,156 KB
testcase_06 AC 1,071 ms
170,892 KB
testcase_07 AC 1,087 ms
168,436 KB
testcase_08 AC 76 ms
76,296 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 = [-1] * 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 = []
ans = 0
for i in range(N):
    a = A[i]
    if dat[a] >= 0:
        ans += a
        unit(i,dat[a])
        continue
    for j in range(a,C,a):
        dat[j] = i
    for j in range(i + 1,N):
        if A[j] % a == 0:continue
        l.append((lcm(a,A[j]),i,j))
l.sort(key = lambda x:x[0])
for t,i,j in l:
    if not isSame(i,j):
        ans += t
        unit(i,j)
print(ans)
0