結果

問題 No.14 最小公倍数ソート
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2016-09-25 20:33:19
言語 Crystal
(1.10.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 447 bytes
コンパイル時間 18,494 ms
コンパイル使用メモリ 253,276 KB
実行使用メモリ 5,308 KB
最終ジャッジ日時 2023-09-13 09:24:19
合計ジャッジ時間 27,367 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,388 KB
testcase_01 AC 3 ms
4,396 KB
testcase_02 AC 2 ms
4,448 KB
testcase_03 AC 55 ms
4,444 KB
testcase_04 TLE -
testcase_05 AC 1,726 ms
4,920 KB
testcase_06 AC 2,009 ms
4,968 KB
testcase_07 AC 2,619 ms
4,896 KB
testcase_08 AC 3,437 ms
5,008 KB
testcase_09 AC 4,648 ms
5,208 KB
testcase_10 AC 4,598 ms
5,140 KB
testcase_11 AC 4,742 ms
5,292 KB
testcase_12 AC 4,863 ms
5,172 KB
testcase_13 AC 4,920 ms
5,308 KB
testcase_14 AC 4,794 ms
5,152 KB
testcase_15 AC 4,949 ms
5,124 KB
testcase_16 AC 1,841 ms
4,848 KB
testcase_17 AC 1,317 ms
4,968 KB
testcase_18 AC 590 ms
4,700 KB
testcase_19 AC 3,109 ms
5,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.to_s.to_i
list = gets.to_s.split.map {|s|s.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)
    next unless x_lcm < m_lcm || (x_lcm == m_lcm && x_num < m_num)
    m = x
    m_num = x_num
    m_lcm = x_lcm
  end
  if m != i + 1
    list[i + 1], list[m] = list[m], list[i + 1]
  end
end
puts list.join(' ')
0