結果

問題 No.365 ジェンガソート
ユーザー k_ab_ok_ab_o
提出日時 2017-01-25 15:29:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 975 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 11,516 KB
実行使用メモリ 25,012 KB
最終ジャッジ日時 2023-08-24 22:57:51
合計ジャッジ時間 6,826 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,392 KB
testcase_01 AC 81 ms
15,108 KB
testcase_02 AC 80 ms
15,272 KB
testcase_03 AC 80 ms
15,028 KB
testcase_04 AC 79 ms
15,320 KB
testcase_05 AC 82 ms
15,136 KB
testcase_06 AC 81 ms
15,160 KB
testcase_07 AC 81 ms
15,132 KB
testcase_08 AC 79 ms
15,152 KB
testcase_09 AC 81 ms
15,256 KB
testcase_10 AC 79 ms
15,256 KB
testcase_11 AC 78 ms
15,256 KB
testcase_12 AC 80 ms
15,120 KB
testcase_13 AC 80 ms
15,280 KB
testcase_14 AC 79 ms
15,248 KB
testcase_15 AC 80 ms
15,216 KB
testcase_16 AC 135 ms
22,312 KB
testcase_17 AC 145 ms
23,960 KB
testcase_18 AC 82 ms
15,512 KB
testcase_19 AC 133 ms
22,608 KB
testcase_20 AC 95 ms
17,472 KB
testcase_21 AC 96 ms
16,844 KB
testcase_22 AC 135 ms
21,764 KB
testcase_23 AC 111 ms
19,144 KB
testcase_24 AC 129 ms
21,728 KB
testcase_25 AC 94 ms
16,916 KB
testcase_26 AC 121 ms
20,368 KB
testcase_27 AC 158 ms
24,760 KB
testcase_28 AC 122 ms
20,464 KB
testcase_29 AC 140 ms
23,216 KB
testcase_30 AC 122 ms
20,596 KB
testcase_31 AC 100 ms
17,312 KB
testcase_32 AC 98 ms
17,468 KB
testcase_33 AC 157 ms
24,260 KB
testcase_34 AC 92 ms
16,500 KB
testcase_35 AC 132 ms
21,628 KB
testcase_36 AC 132 ms
23,228 KB
testcase_37 AC 130 ms
23,112 KB
testcase_38 AC 157 ms
25,012 KB
testcase_39 AC 136 ms
23,136 KB
testcase_40 AC 144 ms
24,608 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 execute
    sorting = []
    keeping = []
    prev = nil
    @block_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
    @answer = sorting.size

    # まだ並んでないなら再度並べる
    if sorting.size > 0 and keeping[0] < sorting.max
      sorting2 = []
      prev2 = nil
      (sorting.sort + keeping).each do |n|
        if prev2.nil?
          prev2 = n
          next
        end

        if prev2 > n
          sorting2 << n
        else
          prev2 = n
        end
      end
      @answer += sorting2.size
    end
  end
end

if $0 == __FILE__
  ins = Xxx.new
  ins.set_inputs
  ins.execute
  puts ins.answer
end
0