結果
問題 | No.1917 LCMST |
ユーザー | chineristAC |
提出日時 | 2022-03-26 22:49:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,448 ms / 4,000 ms |
コード長 | 2,090 bytes |
コンパイル時間 | 566 ms |
コンパイル使用メモリ | 81,844 KB |
実行使用メモリ | 314,504 KB |
最終ジャッジ日時 | 2024-06-28 08:04:16 |
合計ジャッジ時間 | 52,174 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
70,668 KB |
testcase_01 | AC | 64 ms
70,976 KB |
testcase_02 | AC | 64 ms
70,684 KB |
testcase_03 | AC | 120 ms
79,732 KB |
testcase_04 | AC | 120 ms
79,952 KB |
testcase_05 | AC | 115 ms
79,804 KB |
testcase_06 | AC | 113 ms
79,664 KB |
testcase_07 | AC | 117 ms
80,048 KB |
testcase_08 | AC | 67 ms
70,744 KB |
testcase_09 | AC | 2,169 ms
314,504 KB |
testcase_10 | AC | 2,149 ms
314,264 KB |
testcase_11 | AC | 2,082 ms
313,832 KB |
testcase_12 | AC | 1,724 ms
293,152 KB |
testcase_13 | AC | 697 ms
244,280 KB |
testcase_14 | AC | 1,895 ms
309,036 KB |
testcase_15 | AC | 524 ms
242,504 KB |
testcase_16 | AC | 733 ms
244,536 KB |
testcase_17 | AC | 1,003 ms
245,828 KB |
testcase_18 | AC | 1,224 ms
255,640 KB |
testcase_19 | AC | 587 ms
243,880 KB |
testcase_20 | AC | 472 ms
243,356 KB |
testcase_21 | AC | 595 ms
242,648 KB |
testcase_22 | AC | 479 ms
243,180 KB |
testcase_23 | AC | 469 ms
243,572 KB |
testcase_24 | AC | 583 ms
242,224 KB |
testcase_25 | AC | 489 ms
243,020 KB |
testcase_26 | AC | 507 ms
242,272 KB |
testcase_27 | AC | 529 ms
242,360 KB |
testcase_28 | AC | 552 ms
243,292 KB |
testcase_29 | AC | 2,404 ms
301,788 KB |
testcase_30 | AC | 2,424 ms
303,336 KB |
testcase_31 | AC | 2,448 ms
301,888 KB |
testcase_32 | AC | 2,435 ms
302,512 KB |
testcase_33 | AC | 2,448 ms
303,252 KB |
testcase_34 | AC | 275 ms
242,552 KB |
testcase_35 | AC | 274 ms
242,736 KB |
testcase_36 | AC | 273 ms
243,056 KB |
testcase_37 | AC | 2,418 ms
302,508 KB |
testcase_38 | AC | 2,388 ms
303,004 KB |
testcase_39 | AC | 2,414 ms
301,156 KB |
testcase_40 | AC | 2,401 ms
301,884 KB |
testcase_41 | AC | 2,381 ms
301,128 KB |
testcase_42 | AC | 2,291 ms
301,484 KB |
testcase_43 | AC | 325 ms
241,316 KB |
testcase_44 | AC | 322 ms
242,876 KB |
ソースコード
class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) stack = [x] while self._parent[stack[-1]]!=stack[-1]: stack.append(self._parent[stack[-1]]) for v in stack: self._parent[v] = stack[-1] return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import log,gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) M = 10**5 N = int(input()) A = li() res = 0 cnt = [0] * (M+1) for a in A: cnt[a] += 1 val_to_idx = [-1] * (M+1) B = [] for i in range(1,M+1): if cnt[i]: val_to_idx[i] = len(B) B.append(i) res += (cnt[i]-1) * i cnt[i] = 1 n = len(B) edge = [] for val in range(1,M+1): mini = M+1 for i in range(val,M+1,val): if cnt[i]: mini = i break if mini == M+1: continue for i in range(val,M+1,val): if cnt[i] and i!=mini: u = val_to_idx[mini] v = val_to_idx[i] edge.append((mini*i//val,u,v)) edge.sort(key=lambda e:e[0]) uf = UnionFindVerSize(n) for c,u,v in edge: if not uf.is_same_group(u,v): uf.unite(u,v) res += c print(res)