結果

問題 No.1917 LCMST
ユーザー tktk_snsntktk_snsn
提出日時 2022-04-30 09:36:20
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,371 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 849,180 KB
最終ジャッジ日時 2023-09-12 02:02:24
合計ジャッジ時間 8,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
77,412 KB
testcase_01 AC 108 ms
77,436 KB
testcase_02 AC 96 ms
77,636 KB
testcase_03 AC 148 ms
83,292 KB
testcase_04 AC 144 ms
82,960 KB
testcase_05 AC 150 ms
83,124 KB
testcase_06 AC 147 ms
82,268 KB
testcase_07 AC 149 ms
83,016 KB
testcase_08 AC 110 ms
77,484 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 #

from operator import itemgetter


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        stack = []
        while self.root[x] >= 0:
            stack.append(x)
            x = self.root[x]
        for i in stack:
            self.root[i] = x
        return x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return True

    def size(self, x):
        return -self.root[self.find(x)]


U = 10 ** 5 + 10
N = int(input())
A = list(map(int, input().split()))

X = [[] for _ in range(U)]
for i, a in enumerate(A):
    X[a].append(i)

E = []
for d in range(1, U):
    idx = []
    for i in range(d, U, d):
        idx.extend(X[i])
    if not idx:
        continue
    i, *idx = idx
    for j in idx:
        E.append((i, j, A[i] * A[j] // d))

E.sort(key=itemgetter(2))
uf = UF_tree(N)
ans = 0
for a, b, c in E:
    if uf.unite(a, b):
        ans += c
print(ans)
0