結果
問題 | No.1917 LCMST |
ユーザー | mkawa2 |
提出日時 | 2022-10-10 12:59:58 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,519 bytes |
コンパイル時間 | 219 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 623,608 KB |
最終ジャッジ日時 | 2024-06-24 08:02:22 |
合計ジャッジ時間 | 13,754 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 80 ms
73,344 KB |
testcase_01 | AC | 79 ms
67,968 KB |
testcase_02 | AC | 78 ms
67,968 KB |
testcase_03 | AC | 708 ms
119,808 KB |
testcase_04 | AC | 589 ms
110,464 KB |
testcase_05 | AC | 675 ms
115,200 KB |
testcase_06 | AC | 658 ms
116,480 KB |
testcase_07 | AC | 689 ms
116,352 KB |
testcase_08 | AC | 79 ms
67,968 KB |
testcase_09 | MLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True def size(self, u): return self.size_table[self.root(u)] from heapq import * # m = 10 m=100001 n = II() aa = LI() idx = [[] for _ in range(m)] for i, a in enumerate(aa): idx[a].append(i) gtoa = [[] for _ in range(m)] for g in range(1, m)[::-1]: for h in range(g, m, g): if idx[h]: gtoa[g] += [(h, i) for i in idx[h]] # pDB(gtoa) hp = [] for g in range(1, m): if len(gtoa[g]) < 2: continue a, i = gtoa[g][0] b, j = gtoa[g][1] heappush(hp, (a*b//g, g, 0, 1)) uf = UnionFind(n) cnt = n-1 ans = 0 fin = set() while cnt: w, g, l, r = heappop(hp) _, i = gtoa[g][l] _, j = gtoa[g][r] if uf.merge(i, j): ans += w cnt -= 1 if (g, l, r+1) not in fin and r+1 < len(gtoa[g]): fin.add((g, l, r+1)) a, _ = gtoa[g][l] b, _ = gtoa[g][r+1] heappush(hp, (a*b//g, g, l, r+1)) if l+1 < r and (g, l+1, r) not in fin: fin.add((g, l+1, r)) a, _ = gtoa[g][l+1] b, _ = gtoa[g][r] heappush(hp, (a*b//g, g, l+1, r)) print(ans)