結果

問題 No.365 ジェンガソート
ユーザー k_ab_ok_ab_o
提出日時 2017-01-25 16:00:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,588 KB
実行使用メモリ 25,980 KB
最終ジャッジ日時 2023-08-24 22:58:20
合計ジャッジ時間 6,170 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,136 KB
testcase_01 AC 78 ms
15,124 KB
testcase_02 AC 82 ms
15,276 KB
testcase_03 AC 83 ms
15,032 KB
testcase_04 AC 87 ms
15,260 KB
testcase_05 AC 82 ms
15,144 KB
testcase_06 AC 79 ms
15,032 KB
testcase_07 AC 78 ms
15,136 KB
testcase_08 AC 82 ms
15,024 KB
testcase_09 AC 82 ms
15,168 KB
testcase_10 AC 82 ms
15,036 KB
testcase_11 AC 80 ms
15,224 KB
testcase_12 AC 79 ms
15,256 KB
testcase_13 AC 78 ms
15,120 KB
testcase_14 AC 78 ms
15,088 KB
testcase_15 AC 82 ms
15,292 KB
testcase_16 AC 138 ms
22,424 KB
testcase_17 AC 151 ms
24,948 KB
testcase_18 AC 86 ms
15,380 KB
testcase_19 AC 133 ms
22,456 KB
testcase_20 AC 99 ms
17,284 KB
testcase_21 AC 99 ms
17,084 KB
testcase_22 AC 136 ms
22,408 KB
testcase_23 AC 113 ms
19,448 KB
testcase_24 AC 130 ms
22,248 KB
testcase_25 AC 93 ms
17,072 KB
testcase_26 AC 120 ms
20,836 KB
testcase_27 AC 159 ms
25,856 KB
testcase_28 AC 123 ms
20,656 KB
testcase_29 AC 144 ms
23,704 KB
testcase_30 AC 123 ms
20,804 KB
testcase_31 AC 101 ms
17,584 KB
testcase_32 AC 100 ms
17,336 KB
testcase_33 AC 157 ms
25,720 KB
testcase_34 AC 92 ms
16,296 KB
testcase_35 AC 133 ms
22,136 KB
testcase_36 AC 130 ms
23,404 KB
testcase_37 AC 129 ms
23,144 KB
testcase_38 AC 165 ms
25,980 KB
testcase_39 AC 131 ms
23,440 KB
testcase_40 AC 143 ms
25,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:40: warning: assigned but unused variable - buf
Syntax OK

ソースコード

diff #

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
0