結果

問題 No.14 最小公倍数ソート
ユーザー gew1fw
提出日時 2025-06-12 20:46:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 445 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 81,944 KB
実行使用メモリ 235,764 KB
最終ジャッジ日時 2025-06-12 20:46:49
合計ジャッジ時間 7,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def lcm(a, b):
    if a == 0 or b == 0:
        return 0
    if a < b:
        a, b = b, a  # Ensure a >= b
    if a % b == 0:
        return a
    return a * b // math.gcd(a, b)

n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))

for i in range(n-1):
    x = arr[i]
    sub = arr[i+1:]
    sub.sort(key=lambda elem: (lcm(x, elem), elem))
    arr[i+1:] = sub

print(' '.join(map(str, arr)))
0