結果
問題 | No.1917 LCMST |
ユーザー | 👑 rin204 |
提出日時 | 2022-05-05 14:27:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,198 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 267,408 KB |
最終ジャッジ日時 | 2024-07-04 15:53:59 |
合計ジャッジ時間 | 23,019 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,480 KB |
testcase_01 | AC | 36 ms
52,736 KB |
testcase_02 | AC | 39 ms
58,624 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 40 ms
52,736 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 580 ms
265,732 KB |
testcase_30 | AC | 575 ms
266,008 KB |
testcase_31 | AC | 580 ms
266,124 KB |
testcase_32 | AC | 593 ms
264,208 KB |
testcase_33 | AC | 595 ms
266,516 KB |
testcase_34 | AC | 283 ms
230,768 KB |
testcase_35 | AC | 283 ms
230,884 KB |
testcase_36 | AC | 273 ms
231,412 KB |
testcase_37 | AC | 594 ms
266,252 KB |
testcase_38 | AC | 601 ms
266,380 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
ソースコード
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 isprime = [True] * (ma + 1) edges = set() for i in range(1, ma + 1): if not isprime[i]: continue 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)) if i != 1 and i != j: isprime[j] = False 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)