結果
| 問題 | No.365 ジェンガソート | 
| コンテスト | |
| ユーザー |  k_ab_o | 
| 提出日時 | 2017-01-25 16:00:35 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 151 ms / 2,000 ms | 
| コード長 | 876 bytes | 
| コンパイル時間 | 44 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 22,528 KB | 
| 最終ジャッジ日時 | 2024-12-23 09:24:32 | 
| 合計ジャッジ時間 | 5,589 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 41 | 
コンパイルメッセージ
Main.rb:40: warning: assigned but unused variable - buf Syntax OK
ソースコード
class Xxx
  attr_accessor :answer
  def initialize
    @answer = 0
  end
  def set_inputs
    @n = gets.chomp.to_i
    @block_lens = gets.chomp.split(" ").map{|n| n.to_i}
  end
  def sort_proc(lens)
    sorting = []
    keeping = []
    prev = nil
    lens.each do |n|
      if prev.nil?
        prev = n
        keeping << n
        next
      end
      if prev > n
        sorting << n
      else
        keeping << n
        prev = n
      end
    end
    return [sorting, keeping]
  end
  def execute
    sorting, keeping = sort_proc(@block_lens)
    @answer = sorting.size
    # まだ並んでないなら再度並べる
    if sorting.size > 0 and keeping[0] < sorting.max
      sorting, buf = sort_proc(sorting.sort + keeping)
      @answer += sorting.size
    end
  end
end
if $0 == __FILE__
  ins = Xxx.new
  ins.set_inputs
  ins.execute
  puts ins.answer
end
            
            
            
        