結果

問題 No.14 最小公倍数ソート
ユーザー titiatitia
提出日時 2021-11-02 17:58:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,838 ms / 5,000 ms
コード長 588 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 77,876 KB
最終ジャッジ日時 2024-04-20 03:55:56
合計ジャッジ時間 44,009 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
54,332 KB
testcase_01 AC 42 ms
54,628 KB
testcase_02 AC 40 ms
55,524 KB
testcase_03 AC 114 ms
67,708 KB
testcase_04 AC 3,838 ms
77,504 KB
testcase_05 AC 1,357 ms
77,328 KB
testcase_06 AC 1,604 ms
77,204 KB
testcase_07 AC 2,086 ms
77,708 KB
testcase_08 AC 2,685 ms
77,408 KB
testcase_09 AC 3,492 ms
77,436 KB
testcase_10 AC 3,527 ms
77,328 KB
testcase_11 AC 3,545 ms
77,876 KB
testcase_12 AC 3,629 ms
77,272 KB
testcase_13 AC 3,660 ms
77,716 KB
testcase_14 AC 3,557 ms
77,472 KB
testcase_15 AC 3,691 ms
77,680 KB
testcase_16 AC 1,713 ms
77,216 KB
testcase_17 AC 1,279 ms
77,204 KB
testcase_18 AC 635 ms
75,504 KB
testcase_19 AC 2,548 ms
77,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
            
    



0