結果

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

ソースコード

diff #

import math

n = int(input())
arr = list(map(int, input().split()))

def lcm(a, b):
    return a * b // math.gcd(a, b)

for i in range(n - 1):
    current = arr[i]
    # Sort the subarray from i+1 to end based on LCM with current and x
    arr[i+1:] = sorted(arr[i+1:], key=lambda x: (lcm(current, x), x))

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