結果

問題 No.14 最小公倍数ソート
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-09-21 16:55:51
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 438 bytes
コンパイル時間 37 ms
コンパイル使用メモリ 11,232 KB
実行使用メモリ 15,280 KB
最終ジャッジ日時 2023-08-10 23:39:30
合計ジャッジ時間 7,561 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,280 KB
testcase_01 AC 77 ms
15,232 KB
testcase_02 AC 76 ms
15,056 KB
testcase_03 AC 199 ms
15,060 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
list = gets.split.map(&:to_i)

(n - 2).times do |i|
  c_num = list[i]

  m = i + 1
  m_num = list[m]
  m_lcm = m_num.lcm(c_num)

  ((i + 2)...n).each do |x|
    x_num = list[x]
    x_lcm = x_num.lcm(c_num)
    if x_lcm < m_lcm || (x_lcm == m_lcm && x_num < m_num)
      m = x
      m_num = x_num
      m_lcm = x_lcm
    end
  end
  if m != i + 1
    list[i + 1], list[m] = list[m], list[i + 1]
  end
end
puts list.join(' ')
0