結果
問題 | No.1917 LCMST |
ユーザー | chineristAC |
提出日時 | 2022-03-01 01:35:52 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,921 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 225,908 KB |
最終ジャッジ日時 | 2024-06-28 08:02:54 |
合計ジャッジ時間 | 13,878 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
62,464 KB |
testcase_01 | AC | 50 ms
62,336 KB |
testcase_02 | AC | 52 ms
62,464 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 51 ms
62,336 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
ソースコード
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 = 5 * 10**4 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 = [] C = [b for b in B] C.sort() C = C[:10] for c in C: for b in B: u = val_to_idx[c] v = val_to_idx[b] edge.append((b*c//gcd(b,c),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)