結果
問題 | No.14 最小公倍数ソート |
ユーザー |
![]() |
提出日時 | 2025-06-12 21:00:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 544 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,616 KB |
実行使用メモリ | 272,100 KB |
最終ジャッジ日時 | 2025-06-12 21:03:51 |
合計ジャッジ時間 | 7,220 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 15 |
ソースコード
import sys import math def lcm(a, b): return a * b // math.gcd(a, b) def main(): input = sys.stdin.read().split() N = int(input[0]) a = list(map(int, input[1:N+1])) for i in range(N - 1): current = a[i] sublist = a[i+1:] keys = [(lcm(current, x), x) for x in sublist] sorted_keys = sorted(keys, key=lambda k: (k[0], k[1])) sorted_sublist = [x for _, x in sorted_keys] a[i+1:] = sorted_sublist print(' '.join(map(str, a))) if __name__ == '__main__': main()