結果
問題 | No.1917 LCMST |
ユーザー | siganai |
提出日時 | 2022-05-01 20:30:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,558 ms / 4,000 ms |
コード長 | 2,360 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 82,436 KB |
実行使用メモリ | 386,124 KB |
最終ジャッジ日時 | 2024-06-30 22:10:57 |
合計ジャッジ時間 | 57,278 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
76,260 KB |
testcase_01 | AC | 74 ms
75,964 KB |
testcase_02 | AC | 72 ms
76,684 KB |
testcase_03 | AC | 130 ms
85,300 KB |
testcase_04 | AC | 126 ms
84,760 KB |
testcase_05 | AC | 129 ms
85,388 KB |
testcase_06 | AC | 125 ms
85,124 KB |
testcase_07 | AC | 123 ms
84,644 KB |
testcase_08 | AC | 72 ms
76,244 KB |
testcase_09 | AC | 2,482 ms
383,520 KB |
testcase_10 | AC | 2,328 ms
383,880 KB |
testcase_11 | AC | 2,230 ms
375,168 KB |
testcase_12 | AC | 2,087 ms
338,220 KB |
testcase_13 | AC | 795 ms
254,988 KB |
testcase_14 | AC | 1,975 ms
337,036 KB |
testcase_15 | AC | 583 ms
254,972 KB |
testcase_16 | AC | 782 ms
254,492 KB |
testcase_17 | AC | 1,072 ms
285,264 KB |
testcase_18 | AC | 1,412 ms
312,332 KB |
testcase_19 | AC | 555 ms
254,792 KB |
testcase_20 | AC | 466 ms
254,824 KB |
testcase_21 | AC | 598 ms
254,448 KB |
testcase_22 | AC | 470 ms
254,680 KB |
testcase_23 | AC | 463 ms
255,100 KB |
testcase_24 | AC | 572 ms
254,372 KB |
testcase_25 | AC | 480 ms
254,748 KB |
testcase_26 | AC | 489 ms
254,440 KB |
testcase_27 | AC | 520 ms
254,444 KB |
testcase_28 | AC | 533 ms
255,176 KB |
testcase_29 | AC | 2,545 ms
385,768 KB |
testcase_30 | AC | 2,536 ms
385,604 KB |
testcase_31 | AC | 2,466 ms
385,756 KB |
testcase_32 | AC | 2,526 ms
385,548 KB |
testcase_33 | AC | 2,519 ms
385,888 KB |
testcase_34 | AC | 278 ms
256,636 KB |
testcase_35 | AC | 274 ms
256,316 KB |
testcase_36 | AC | 279 ms
256,636 KB |
testcase_37 | AC | 2,519 ms
385,520 KB |
testcase_38 | AC | 2,496 ms
385,524 KB |
testcase_39 | AC | 2,528 ms
385,948 KB |
testcase_40 | AC | 2,536 ms
386,124 KB |
testcase_41 | AC | 2,558 ms
385,780 KB |
testcase_42 | AC | 2,518 ms
383,908 KB |
testcase_43 | AC | 316 ms
254,568 KB |
testcase_44 | AC | 312 ms
255,000 KB |
ソースコード
#!/usr/bin/env PyPy3 from collections import Counter, defaultdict, deque import itertools import re import math from functools import reduce import operator import bisect from heapq import * import functools mod=998244353 import sys input=sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): now = x tmpl = [] while self.parents[now] >= 0: tmpl.append(now) now = self.parents[now] for xx in tmpl: self.parents[xx] = now return now def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return x if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x return 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):#O(n)かかる。全部求めたい場合は、all_group_membersを使う。 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 len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) maxa = 10 ** 5 + 1 n = int(input()) a = list(map(int,input().split())) l = [-1] * maxa uf = UnionFind(n) ans = 0 for i,aa in enumerate(a): if l[aa] == -1: l[aa] = i else: ans += aa ca = [[] for _ in range(maxa)] for i in range(1,maxa): for j in range(1,maxa): if i * j > maxa - 1: break if l[i * j] != -1: ca[i].append([i * j,l[i * j]]) edge = [] for i in range(1,maxa): for j in range(1,len(ca[i])): edge.append([ca[i][0][0] * ca[i][j][0] // i,ca[i][0][1],ca[i][j][1]]) edge.sort(key = operator.itemgetter(0)) for dis,i,j in edge: if uf.same(i,j): continue ans += dis uf.union(i,j) print(ans)