結果

問題 No.14 最小公倍数ソート
ユーザー gew1fw
提出日時 2025-06-12 16:08:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 583 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 270,448 KB
最終ジャッジ日時 2025-06-12 16:09:02
合計ジャッジ時間 7,481 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    n = int(data[0])
    a = list(map(int, data[1:n+1]))
    
    for i in range(n-1):
        current = a[i]
        sub = a[i+1:]
        # Create a list of tuples (lcm, x)
        keys = [(current * x // math.gcd(current, x), x) for x in sub]
        # Sort the subarray based on the keys
        sorted_sub = [x for _, x in sorted(zip(keys, sub))]
        # Update the array
        a[i+1:] = sorted_sub
    
    print(' '.join(map(str, a)))

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