結果

問題 No.14 最小公倍数ソート
ユーザー gigurururugigurururu
提出日時 2014-12-31 13:14:42
言語 Ruby
(3.2.2)
結果
AC  
実行時間 511 ms / 5,000 ms
コード長 377 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 17,904 KB
最終ジャッジ日時 2023-08-27 05:25:41
合計ジャッジ時間 8,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
15,512 KB
testcase_01 AC 96 ms
15,140 KB
testcase_02 AC 96 ms
15,356 KB
testcase_03 AC 124 ms
15,704 KB
testcase_04 AC 511 ms
17,832 KB
testcase_05 AC 276 ms
16,372 KB
testcase_06 AC 304 ms
17,032 KB
testcase_07 AC 350 ms
17,240 KB
testcase_08 AC 409 ms
17,264 KB
testcase_09 AC 479 ms
17,672 KB
testcase_10 AC 471 ms
17,792 KB
testcase_11 AC 489 ms
17,676 KB
testcase_12 AC 492 ms
17,676 KB
testcase_13 AC 500 ms
17,756 KB
testcase_14 AC 489 ms
17,664 KB
testcase_15 AC 504 ms
17,904 KB
testcase_16 AC 297 ms
17,140 KB
testcase_17 AC 257 ms
16,936 KB
testcase_18 AC 194 ms
16,344 KB
testcase_19 AC 386 ms
17,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require'prime'
N=gets.to_i
a=gets.split.map(&:to_i)
div=Hash.new{|h,x|
  h[x]=x.prime_division.inject([1]){|s,(p,k)|
    s+s.flat_map{|i|(1..k).map{|j|i*p**j}}
  }
}
mul=(0..a.max).map{[]}
a.sort.each{|i|
  div[i].each{|d|
    mul[d] << i
  }
}
puts ([i=a[0]]+(2..N).map{
  i=div[i].map{|d|
    mul[d].delete_at(mul[d].index i)
    (t=mul[d][0])?[t/d,t]:[1e9]
  }.min[1]
})*" "
0