結果
問題 | No.365 ジェンガソート |
ユーザー |
![]() |
提出日時 | 2017-01-25 15:29:58 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 52 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 21,760 KB |
最終ジャッジ日時 | 2024-12-23 09:24:10 |
合計ジャッジ時間 | 6,078 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
コンパイルメッセージ
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 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