結果

問題 No.14 最小公倍数ソート
ユーザー titiatitia
提出日時 2021-11-02 13:06:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,955 ms / 5,000 ms
コード長 586 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 78,228 KB
最終ジャッジ日時 2024-04-19 19:57:13
合計ジャッジ時間 54,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,132 KB
testcase_01 AC 45 ms
54,016 KB
testcase_02 AC 42 ms
53,760 KB
testcase_03 AC 139 ms
68,224 KB
testcase_04 AC 4,955 ms
77,736 KB
testcase_05 AC 1,680 ms
77,460 KB
testcase_06 AC 2,048 ms
77,440 KB
testcase_07 AC 2,691 ms
77,476 KB
testcase_08 AC 3,610 ms
77,488 KB
testcase_09 AC 4,640 ms
77,496 KB
testcase_10 AC 4,634 ms
77,436 KB
testcase_11 AC 4,812 ms
77,440 KB
testcase_12 AC 4,843 ms
78,228 KB
testcase_13 AC 4,905 ms
77,564 KB
testcase_14 AC 4,702 ms
77,372 KB
testcase_15 AC 4,774 ms
77,572 KB
testcase_16 AC 2,146 ms
77,860 KB
testcase_17 AC 1,593 ms
77,456 KB
testcase_18 AC 793 ms
75,480 KB
testcase_19 AC 3,299 ms
77,732 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:
            if lcm(a,x)<MIN or (x<now and MIN==lcm(a,x)):
                MIN=lcm(a,x)
                now=x
        ANS.append(now)
        X[now]-=1
        if X[now]==0:
            del X[now]
print(*ANS)
            
    



0