結果

問題 No.14 最小公倍数ソート
ユーザー titiatitia
提出日時 2021-11-02 17:57:36
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 3,925 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 78,848 KB
最終ジャッジ日時 2023-08-02 03:37:50
合計ジャッジ時間 46,820 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,532 KB
testcase_01 AC 69 ms
71,764 KB
testcase_02 AC 70 ms
71,428 KB
testcase_03 AC 140 ms
76,884 KB
testcase_04 AC 3,810 ms
78,660 KB
testcase_05 AC 1,405 ms
77,060 KB
testcase_06 AC 1,674 ms
77,228 KB
testcase_07 AC 2,150 ms
78,264 KB
testcase_08 AC 2,793 ms
78,392 KB
testcase_09 AC 3,706 ms
78,360 KB
testcase_10 AC 3,693 ms
78,132 KB
testcase_11 AC 3,745 ms
78,396 KB
testcase_12 AC 3,873 ms
78,288 KB
testcase_13 AC 3,925 ms
78,472 KB
testcase_14 AC 3,608 ms
78,188 KB
testcase_15 AC 3,759 ms
78,848 KB
testcase_16 AC 1,691 ms
77,196 KB
testcase_17 AC 1,224 ms
76,952 KB
testcase_18 AC 648 ms
76,928 KB
testcase_19 AC 2,654 ms
78,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def lcm(x,y):
    return x*y//gcd(x,y)

N=int(input())
A=list(map(int,input().split()))

ANS=[A[0]]
X=sorted(A[1:])
USE=[0]*(N-1)

for tests in range(N-1):
    a=ANS[-1]

    MIN=1<<30
    now=-1
    for i in range(N-1):
        if USE[i]==1:
            continue
        k=lcm(a,X[i])
        if k<MIN:
            MIN=k
            now=i
        if X[i]>=MIN:
            break
    ANS.append(X[now])
    USE[now]=1

print(*ANS)
            
    



0