結果

問題 No.14 最小公倍数ソート
ユーザー lam6er
提出日時 2025-03-31 17:38:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 540 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,736 KB
実行使用メモリ 76,568 KB
最終ジャッジ日時 2025-03-31 17:39:39
合計ジャッジ時間 8,020 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from math import gcd

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    for i in range(n-1):
        x = a[i]
        start = i + 1
        # Create a slice of the list from start to end
        tail = a[start:]
        # Sort the slice based on LCM with x and then by the element's value
        tail.sort(key=lambda y: (x * y // gcd(x, y), y))
        # Replace the slice in the original list
        a[start:] = tail
    
    print(' '.join(map(str, a)))

if __name__ == "__main__":
    main()
0