結果

問題 No.14 最小公倍数ソート
ユーザー zimphazimpha
提出日時 2017-12-07 21:22:32
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 495 bytes
コンパイル時間 1,946 ms
コンパイル使用メモリ 86,552 KB
実行使用メモリ 90,444 KB
最終ジャッジ日時 2023-08-19 12:21:35
合計ジャッジ時間 6,216 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,080 KB
testcase_01 AC 89 ms
71,016 KB
testcase_02 AC 88 ms
70,980 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

upp = 1000
mem = [[-1] * upp for i in range(upp)]
def fast_gcd(x, y):
  if x < upp and y < upp and mem[x][y] != -1:
    return mem[x][y]
  mem[x][y] = x if not y else fast_gcd(y, x % y)
  return mem[x][y]

n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1):
  x = i + 1
  r = a[x] / fast_gcd(a[i], a[x])
  for j in range(i + 2, n):
    t = a[j] / fast_gcd(a[i], a[j])
    if t < r or (t == r and a[j] < a[x]):
      r, x = t, j
  a[i + 1], a[x] = a[x], a[i + 1]
print(*a)
0