結果
問題 |
No.366 ロボットソート
|
ユーザー |
|
提出日時 | 2017-03-06 02:54:59 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 447 bytes |
コンパイル時間 | 189 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-06-23 06:11:27 |
合計ジャッジ時間 | 2,881 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n,k=gets.split.map(&:to_i) aa=gets.split.map(&:to_i) @cnt=0 def solve_sort!(arr,left,right,hop) return if left >= right i=right j=right-hop while (left<=j) if arr[j]>arr[i] arr[i],arr[j]=arr[j],arr[i] @cnt+=1 end i-=hop j-=hop end solve_sort!(arr,left+hop,right,hop) end def sorted?(aa) aa.inject{|s,e|!s||s>e ? false : e} end k.times{|i| solve_sort!(aa,0,aa.size-1-i,k) } p sorted?(aa) ? @cnt : -1