結果
問題 | No.1917 LCMST |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-05 14:26:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,341 ms / 4,000 ms |
コード長 | 2,069 bytes |
コンパイル時間 | 392 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 271,688 KB |
最終ジャッジ日時 | 2024-07-04 15:53:10 |
合計ジャッジ時間 | 31,780 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,352 KB |
testcase_01 | AC | 42 ms
52,480 KB |
testcase_02 | AC | 47 ms
59,776 KB |
testcase_03 | AC | 98 ms
77,568 KB |
testcase_04 | AC | 87 ms
75,008 KB |
testcase_05 | AC | 95 ms
77,056 KB |
testcase_06 | AC | 91 ms
75,136 KB |
testcase_07 | AC | 88 ms
75,264 KB |
testcase_08 | AC | 41 ms
52,736 KB |
testcase_09 | AC | 967 ms
266,408 KB |
testcase_10 | AC | 979 ms
267,036 KB |
testcase_11 | AC | 998 ms
265,368 KB |
testcase_12 | AC | 1,341 ms
261,504 KB |
testcase_13 | AC | 664 ms
250,336 KB |
testcase_14 | AC | 933 ms
261,756 KB |
testcase_15 | AC | 602 ms
245,748 KB |
testcase_16 | AC | 662 ms
249,476 KB |
testcase_17 | AC | 1,011 ms
251,136 KB |
testcase_18 | AC | 1,139 ms
252,804 KB |
testcase_19 | AC | 601 ms
254,336 KB |
testcase_20 | AC | 564 ms
253,188 KB |
testcase_21 | AC | 609 ms
257,276 KB |
testcase_22 | AC | 564 ms
251,528 KB |
testcase_23 | AC | 567 ms
252,804 KB |
testcase_24 | AC | 605 ms
256,964 KB |
testcase_25 | AC | 567 ms
254,340 KB |
testcase_26 | AC | 586 ms
251,788 KB |
testcase_27 | AC | 585 ms
253,440 KB |
testcase_28 | AC | 602 ms
250,244 KB |
testcase_29 | AC | 973 ms
266,532 KB |
testcase_30 | AC | 989 ms
271,572 KB |
testcase_31 | AC | 984 ms
271,676 KB |
testcase_32 | AC | 992 ms
265,504 KB |
testcase_33 | AC | 1,001 ms
271,688 KB |
testcase_34 | AC | 288 ms
230,144 KB |
testcase_35 | AC | 288 ms
230,784 KB |
testcase_36 | AC | 289 ms
231,168 KB |
testcase_37 | AC | 980 ms
265,512 KB |
testcase_38 | AC | 995 ms
265,256 KB |
testcase_39 | AC | 996 ms
265,112 KB |
testcase_40 | AC | 995 ms
266,148 KB |
testcase_41 | AC | 973 ms
265,768 KB |
testcase_42 | AC | 975 ms
266,148 KB |
testcase_43 | AC | 345 ms
243,456 KB |
testcase_44 | AC | 348 ms
243,076 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 def f(g, i, j): return (g * l + i) * l + j 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(f(B[ii] * B[jj] // gcd(B[ii], B[jj]), ii, jj)) edges = sorted(edges) UF = UnionFind(n) for tmp in edges: j = tmp % l tmp //= l c = tmp // l i = tmp - c * l if not UF.same(i, j): ans += c UF.union(i, j) print(ans)