結果
問題 | No.1917 LCMST |
ユーザー | chineristAC |
提出日時 | 2022-04-05 00:07:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,366 ms / 4,000 ms |
コード長 | 2,073 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 306,228 KB |
最終ジャッジ日時 | 2024-06-28 08:07:00 |
合計ジャッジ時間 | 66,217 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
69,940 KB |
testcase_01 | AC | 63 ms
70,040 KB |
testcase_02 | AC | 63 ms
69,976 KB |
testcase_03 | AC | 121 ms
80,128 KB |
testcase_04 | AC | 120 ms
79,960 KB |
testcase_05 | AC | 122 ms
79,932 KB |
testcase_06 | AC | 115 ms
79,960 KB |
testcase_07 | AC | 119 ms
79,900 KB |
testcase_08 | AC | 66 ms
71,584 KB |
testcase_09 | AC | 2,871 ms
303,908 KB |
testcase_10 | AC | 2,880 ms
304,524 KB |
testcase_11 | AC | 2,805 ms
303,812 KB |
testcase_12 | AC | 2,253 ms
284,596 KB |
testcase_13 | AC | 824 ms
244,276 KB |
testcase_14 | AC | 2,480 ms
286,216 KB |
testcase_15 | AC | 569 ms
243,080 KB |
testcase_16 | AC | 875 ms
243,264 KB |
testcase_17 | AC | 1,222 ms
245,772 KB |
testcase_18 | AC | 1,503 ms
245,940 KB |
testcase_19 | AC | 692 ms
243,048 KB |
testcase_20 | AC | 496 ms
242,960 KB |
testcase_21 | AC | 726 ms
243,632 KB |
testcase_22 | AC | 509 ms
242,708 KB |
testcase_23 | AC | 503 ms
242,244 KB |
testcase_24 | AC | 699 ms
243,152 KB |
testcase_25 | AC | 524 ms
243,848 KB |
testcase_26 | AC | 579 ms
241,856 KB |
testcase_27 | AC | 621 ms
243,428 KB |
testcase_28 | AC | 644 ms
241,604 KB |
testcase_29 | AC | 3,320 ms
304,892 KB |
testcase_30 | AC | 3,298 ms
304,824 KB |
testcase_31 | AC | 3,290 ms
306,228 KB |
testcase_32 | AC | 3,311 ms
305,496 KB |
testcase_33 | AC | 3,366 ms
305,196 KB |
testcase_34 | AC | 265 ms
243,792 KB |
testcase_35 | AC | 260 ms
242,372 KB |
testcase_36 | AC | 265 ms
242,240 KB |
testcase_37 | AC | 3,261 ms
304,560 KB |
testcase_38 | AC | 3,220 ms
305,076 KB |
testcase_39 | AC | 3,165 ms
304,820 KB |
testcase_40 | AC | 3,219 ms
305,580 KB |
testcase_41 | AC | 3,198 ms
303,920 KB |
testcase_42 | AC | 3,140 ms
303,816 KB |
testcase_43 | AC | 305 ms
241,352 KB |
testcase_44 | AC | 314 ms
242,496 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() 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)