結果
| 問題 | No.14 最小公倍数ソート |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-01-21 12:31:05 |
| 言語 | PyPy3 (8.0.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 87 ms / 5,000 ms |
| + 20µs | |
| コード長 | 1,291 bytes |
| 記録 | |
| コンパイル時間 | 67 ms |
| コンパイル使用メモリ | 81,656 KB |
| 実行使用メモリ | 85,704 KB |
| 最終ジャッジ日時 | 2026-09-29 18:00:04 |
| 合計ジャッジ時間 | 2,933 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
import itertools
import sys
input = sys.stdin.readline
def main():
N = int(input())
*A, = map(int, input().split())
MAX = 10000
cnt = [0]*(MAX+1)
for a in A[1:]:
cnt[a] += 1
ptr = list(range(MAX+1))
def getnxt(x):
while ptr[x] <= MAX and cnt[ptr[x]] == 0:
ptr[x] += x
return ptr[x] if ptr[x] <= MAX else None
def getmin(v):
maxv = ans = MAX * MAX
for i in itertools.count(1):
if i*i > v:
return ans
if v % i == 0:
n = getnxt(i)
if n is not None:
l = n * (v // i)
if maxv > l:
maxv = l
ans = n
elif maxv == l:
ans = min(ans, n)
n = getnxt(v // i)
if n is not None:
l = n * i
if maxv > l:
maxv = l
ans = n
elif maxv == l:
ans = min(ans, n)
ans = [A[0]]
while len(ans) != N:
ret = getmin(ans[-1])
ans += [ret]*cnt[ret]
cnt[ret] = 0
print(*ans, sep=' ')
if __name__ == '__main__':
main()