結果
問題 | No.14 最小公倍数ソート |
ユーザー | maspy |
提出日時 | 2020-03-25 00:43:52 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 306 ms / 5,000 ms |
コード長 | 1,839 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 20,352 KB |
最終ジャッジ日時 | 2024-06-10 09:34:31 |
合計ジャッジ時間 | 4,992 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 75 ms
16,896 KB |
testcase_01 | AC | 75 ms
16,768 KB |
testcase_02 | AC | 75 ms
16,768 KB |
testcase_03 | AC | 94 ms
17,280 KB |
testcase_04 | AC | 248 ms
20,352 KB |
testcase_05 | AC | 184 ms
18,944 KB |
testcase_06 | AC | 178 ms
19,072 KB |
testcase_07 | AC | 204 ms
19,456 KB |
testcase_08 | AC | 219 ms
19,712 KB |
testcase_09 | AC | 232 ms
20,224 KB |
testcase_10 | AC | 242 ms
20,352 KB |
testcase_11 | AC | 245 ms
20,352 KB |
testcase_12 | AC | 306 ms
20,352 KB |
testcase_13 | AC | 296 ms
20,352 KB |
testcase_14 | AC | 247 ms
20,352 KB |
testcase_15 | AC | 246 ms
20,352 KB |
testcase_16 | AC | 176 ms
19,328 KB |
testcase_17 | AC | 157 ms
18,944 KB |
testcase_18 | AC | 129 ms
18,432 KB |
testcase_19 | AC | 205 ms
19,712 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 # %%