結果
| 問題 | No.366 ロボットソート | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-03-06 02:50:23 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 447 bytes | 
| コンパイル時間 | 538 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 12,416 KB | 
| 最終ジャッジ日時 | 2024-06-23 06:09:04 | 
| 合計ジャッジ時間 | 3,249 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 15 WA * 8 | 
コンパイルメッセージ
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
            
            
            
        