結果
問題 | No.1917 LCMST |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-05 14:24:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,189 ms / 4,000 ms |
コード長 | 1,957 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 324,316 KB |
最終ジャッジ日時 | 2024-07-04 15:52:14 |
合計ジャッジ時間 | 63,854 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,992 KB |
testcase_01 | AC | 36 ms
52,992 KB |
testcase_02 | AC | 41 ms
59,520 KB |
testcase_03 | AC | 131 ms
78,080 KB |
testcase_04 | AC | 82 ms
77,824 KB |
testcase_05 | AC | 86 ms
77,732 KB |
testcase_06 | AC | 88 ms
77,824 KB |
testcase_07 | AC | 82 ms
77,952 KB |
testcase_08 | AC | 38 ms
52,992 KB |
testcase_09 | AC | 2,529 ms
295,228 KB |
testcase_10 | AC | 2,639 ms
308,248 KB |
testcase_11 | AC | 2,609 ms
314,636 KB |
testcase_12 | AC | 2,114 ms
264,656 KB |
testcase_13 | AC | 903 ms
249,648 KB |
testcase_14 | AC | 2,156 ms
274,604 KB |
testcase_15 | AC | 717 ms
247,704 KB |
testcase_16 | AC | 912 ms
248,140 KB |
testcase_17 | AC | 1,249 ms
249,628 KB |
testcase_18 | AC | 1,613 ms
250,648 KB |
testcase_19 | AC | 698 ms
249,136 KB |
testcase_20 | AC | 577 ms
246,948 KB |
testcase_21 | AC | 713 ms
251,052 KB |
testcase_22 | AC | 593 ms
245,928 KB |
testcase_23 | AC | 584 ms
245,992 KB |
testcase_24 | AC | 721 ms
250,176 KB |
testcase_25 | AC | 593 ms
247,576 KB |
testcase_26 | AC | 643 ms
249,256 KB |
testcase_27 | AC | 662 ms
248,484 KB |
testcase_28 | AC | 664 ms
246,544 KB |
testcase_29 | AC | 2,993 ms
324,308 KB |
testcase_30 | AC | 3,048 ms
324,316 KB |
testcase_31 | AC | 2,994 ms
324,020 KB |
testcase_32 | AC | 3,107 ms
295,800 KB |
testcase_33 | AC | 3,188 ms
323,888 KB |
testcase_34 | AC | 262 ms
231,376 KB |
testcase_35 | AC | 250 ms
231,712 KB |
testcase_36 | AC | 256 ms
232,148 KB |
testcase_37 | AC | 3,168 ms
295,840 KB |
testcase_38 | AC | 3,189 ms
295,844 KB |
testcase_39 | AC | 3,100 ms
294,504 KB |
testcase_40 | AC | 3,076 ms
295,416 KB |
testcase_41 | AC | 3,085 ms
283,852 KB |
testcase_42 | AC | 2,933 ms
291,948 KB |
testcase_43 | AC | 347 ms
246,184 KB |
testcase_44 | AC | 318 ms
244,540 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 = set() 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.add((B[ii] * B[jj] // gcd(B[ii], B[jj]), ii, jj)) edges = sorted(edges) UF = UnionFind(n) for c, i, j in edges: if not UF.same(i, j): ans += c UF.union(i, j) print(ans)