結果
問題 |
No.14 最小公倍数ソート
|
ユーザー |
![]() |
提出日時 | 2021-11-02 17:58:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,006 ms / 5,000 ms |
コード長 | 588 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 82,212 KB |
実行使用メモリ | 77,596 KB |
最終ジャッジ日時 | 2024-10-11 22:49:30 |
合計ジャッジ時間 | 46,344 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
from collections import Counter from math import gcd def lcm(x,y): return x*y//gcd(x,y) N=int(input()) A=list(map(int,input().split())) ANS=[A[0]] X=Counter(A[1:]) while X: if X[1]!=0: ANS.append(1) X[1]-=1 if X[1]==0: del X[1] else: MIN=1<<30 a=ANS[-1] now=-1 for x in X: k=lcm(a,x) if k<MIN or (x<now and MIN==k): MIN=k now=x ANS.append(now) X[now]-=1 if X[now]==0: del X[now] print(*ANS)