結果

問題 No.14 最小公倍数ソート
ユーザー dangodango
提出日時 2023-07-08 09:50:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 437 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 77,832 KB
最終ジャッジ日時 2023-09-29 11:14:00
合計ジャッジ時間 65,314 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,476 KB
testcase_01 AC 72 ms
71,276 KB
testcase_02 AC 72 ms
71,372 KB
testcase_03 AC 150 ms
76,828 KB
testcase_04 TLE -
testcase_05 AC 2,002 ms
77,164 KB
testcase_06 AC 2,323 ms
76,936 KB
testcase_07 AC 3,015 ms
76,936 KB
testcase_08 AC 3,932 ms
77,204 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 AC 2,169 ms
76,880 KB
testcase_17 AC 1,579 ms
77,240 KB
testcase_18 AC 759 ms
76,944 KB
testcase_19 AC 3,578 ms
77,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def lcm(a, b):
    return a * b // math.gcd(a, b)
N = int(input())
A = list(map(int, input().split()))
for i in range(N - 2):
    minlcm = lcm(A[i], A[i + 1])
    index = i + 1
    for j in range(i + 2, N):
        l = lcm(A[i], A[j])
        if l < minlcm:
            minlcm = l
            index = j
        elif l == minlcm and A[index] > A[j]:
            index = j
    A[i + 1], A[index] = A[index], A[i + 1]
print(*A)
0