結果

問題 No.14 最小公倍数ソート
ユーザー titiatitia
提出日時 2021-11-02 17:57:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,210 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 75,040 KB
最終ジャッジ日時 2024-04-20 03:54:13
合計ジャッジ時間 38,633 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
53,332 KB
testcase_01 AC 33 ms
52,932 KB
testcase_02 AC 32 ms
53,068 KB
testcase_03 AC 91 ms
64,912 KB
testcase_04 AC 3,111 ms
73,888 KB
testcase_05 AC 1,140 ms
72,224 KB
testcase_06 AC 1,360 ms
73,636 KB
testcase_07 AC 1,764 ms
72,912 KB
testcase_08 AC 2,292 ms
73,512 KB
testcase_09 AC 3,036 ms
73,404 KB
testcase_10 AC 3,033 ms
73,332 KB
testcase_11 AC 3,064 ms
75,040 KB
testcase_12 AC 3,196 ms
74,128 KB
testcase_13 AC 3,210 ms
73,848 KB
testcase_14 AC 2,952 ms
74,124 KB
testcase_15 AC 3,081 ms
74,332 KB
testcase_16 AC 1,359 ms
72,068 KB
testcase_17 AC 976 ms
71,900 KB
testcase_18 AC 504 ms
68,760 KB
testcase_19 AC 2,150 ms
74,160 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