結果
問題 | No.14 最小公倍数ソート |
ユーザー | maspy |
提出日時 | 2020-03-25 00:43:52 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 281 ms / 5,000 ms |
コード長 | 1,839 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 20,096 KB |
最終ジャッジ日時 | 2025-01-01 19:04:43 |
合計ジャッジ時間 | 5,370 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
16,256 KB |
testcase_01 | AC | 76 ms
16,256 KB |
testcase_02 | AC | 78 ms
16,128 KB |
testcase_03 | AC | 94 ms
16,640 KB |
testcase_04 | AC | 281 ms
19,840 KB |
testcase_05 | AC | 186 ms
18,304 KB |
testcase_06 | AC | 191 ms
18,688 KB |
testcase_07 | AC | 205 ms
18,816 KB |
testcase_08 | AC | 229 ms
19,328 KB |
testcase_09 | AC | 251 ms
19,832 KB |
testcase_10 | AC | 249 ms
19,712 KB |
testcase_11 | AC | 252 ms
19,968 KB |
testcase_12 | AC | 264 ms
19,968 KB |
testcase_13 | AC | 262 ms
19,712 KB |
testcase_14 | AC | 259 ms
20,096 KB |
testcase_15 | AC | 261 ms
19,840 KB |
testcase_16 | AC | 192 ms
18,816 KB |
testcase_17 | AC | 177 ms
18,432 KB |
testcase_18 | AC | 140 ms
17,792 KB |
testcase_19 | AC | 226 ms
19,072 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from heapq import heapify, heappop from collections import defaultdict N, *A = map(int, read().split()) class RemovableHeap(): def __init__(self, data): self.n_elem = len(data) self.data = data heapify(self.data) self.counter = defaultdict(int) for x in data: self.counter[x] += 1 def top(self): while True: x = self.data[0] if not self.counter[x]: heappop(self.data) continue return x def push(self, x): self.counter[x] += 1 heappush(self.data, x) self.n_elem += 1 def pop(self): while True: x = heappop(self.data) if self.counter[x]: self.counter[x] -= 1 self.n_elem -= 1 return x def remove(self, x): self.counter[x] -= 1 self.n_elem -= 1 def empty(self): return self.n_elem == 0 U = 10 ** 4 div = [[] for _ in range(U + 1)] for d in range(1, U + 1): for i in range(d, U + 1, d): div[i].append(d) INF = 10 ** 9 multiples = [[INF] for _ in range(U + 1)] for x in A[1:]: for d in div[x]: multiples[d].append(x) for i in range(1, U + 1): multiples[i] = RemovableHeap(multiples[i]) answer = [A[0]] n = A[0] for _ in range(N - 1): best_lcm = INF best_x = 0 for d in div[n]: x = multiples[d].top() lcm = n * x // d if best_lcm > lcm: best_lcm = lcm best_x = x n = best_x answer.append(n) for d in div[n]: multiples[d].remove(n) print(*answer) # %% # import numpy as np # from numba import njit # %%