結果
問題 | No.1917 LCMST |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-05 14:23:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,501 ms / 4,000 ms |
コード長 | 1,948 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 311,840 KB |
最終ジャッジ日時 | 2024-07-04 15:50:56 |
合計ジャッジ時間 | 72,566 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,480 KB |
testcase_01 | AC | 40 ms
52,608 KB |
testcase_02 | AC | 46 ms
59,392 KB |
testcase_03 | AC | 103 ms
78,208 KB |
testcase_04 | AC | 106 ms
77,568 KB |
testcase_05 | AC | 105 ms
77,696 KB |
testcase_06 | AC | 104 ms
77,952 KB |
testcase_07 | AC | 94 ms
74,752 KB |
testcase_08 | AC | 42 ms
52,480 KB |
testcase_09 | AC | 3,501 ms
308,672 KB |
testcase_10 | AC | 3,321 ms
311,840 KB |
testcase_11 | AC | 3,322 ms
309,756 KB |
testcase_12 | AC | 2,805 ms
282,768 KB |
testcase_13 | AC | 1,144 ms
249,900 KB |
testcase_14 | AC | 3,081 ms
292,404 KB |
testcase_15 | AC | 896 ms
245,932 KB |
testcase_16 | AC | 1,188 ms
248,744 KB |
testcase_17 | AC | 1,613 ms
249,644 KB |
testcase_18 | AC | 2,103 ms
251,052 KB |
testcase_19 | AC | 858 ms
247,352 KB |
testcase_20 | AC | 703 ms
247,468 KB |
testcase_21 | AC | 880 ms
248,416 KB |
testcase_22 | AC | 713 ms
245,288 KB |
testcase_23 | AC | 689 ms
245,816 KB |
testcase_24 | AC | 858 ms
247,976 KB |
testcase_25 | AC | 722 ms
246,828 KB |
testcase_26 | AC | 761 ms
246,072 KB |
testcase_27 | AC | 794 ms
246,704 KB |
testcase_28 | AC | 821 ms
244,196 KB |
testcase_29 | AC | 2,911 ms
301,468 KB |
testcase_30 | AC | 2,931 ms
301,208 KB |
testcase_31 | AC | 2,906 ms
301,112 KB |
testcase_32 | AC | 2,946 ms
300,900 KB |
testcase_33 | AC | 2,975 ms
301,428 KB |
testcase_34 | AC | 292 ms
230,568 KB |
testcase_35 | AC | 295 ms
230,312 KB |
testcase_36 | AC | 284 ms
230,596 KB |
testcase_37 | AC | 2,996 ms
310,900 KB |
testcase_38 | AC | 3,035 ms
310,376 KB |
testcase_39 | AC | 3,024 ms
310,892 KB |
testcase_40 | AC | 3,006 ms
310,240 KB |
testcase_41 | AC | 3,078 ms
310,540 KB |
testcase_42 | AC | 3,246 ms
310,468 KB |
testcase_43 | AC | 359 ms
244,012 KB |
testcase_44 | AC | 355 ms
243,764 KB |
ソースコード
from math import gcd class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n self.group = n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return self.group -= 1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n = int(input()) A = list(map(int, input().split())) A.sort() ma = A[-1] B = [] bef = -1 ans = 0 ind = [-1] * (ma + 1) l = 0 for a in A: if a == bef: ans += a else: B.append(a) bef = a ind[a] = l l += 1 edges = [] for i in range(1, ma + 1): ii = -1 for j in range(i, ma + 1, i): if ind[j] != -1: if ii == -1: ii = ind[j] else: jj = ind[j] edges.append((B[ii] * B[jj] // gcd(B[ii], B[jj]), ii, jj)) edges.sort() UF = UnionFind(n) for c, i, j in edges: if not UF.same(i, j): ans += c UF.union(i, j) print(ans)