結果
| 問題 |
No.14 最小公倍数ソート
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:07:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 544 bytes |
| コンパイル時間 | 212 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 270,592 KB |
| 最終ジャッジ日時 | 2025-06-12 16:07:51 |
| 合計ジャッジ時間 | 7,254 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()
gew1fw