結果

問題 No.14 最小公倍数ソート
ユーザー dangodango
提出日時 2023-07-08 09:32:45
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 486 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 85,556 KB
最終ジャッジ日時 2023-09-29 10:49:20
合計ジャッジ時間 7,620 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,300 KB
testcase_01 AC 69 ms
71,500 KB
testcase_02 AC 66 ms
71,376 KB
testcase_03 AC 324 ms
79,660 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(15 * 10 ** 7)
def gcd(m, n):
  if n == 0:
    return m
  else:
    return gcd(n, m % n)
N = int(input())
A = list(map(int, input().split()))
for i in range(N-1):
    mv = float('inf')
    mj = -1
    for j in range(i+1, N):
        lcm = A[i] * A[j] // gcd(A[i], A[j])
        if lcm < mv:
            mv = lcm
            mj = j
        elif lcm == mv and A[mj] > A[j]:
            mj = j
    A[i+1], A[mj] = A[mj], A[i+1]
print(' '.join(map(str, A)))
0