結果
問題 |
No.714 回転寿司屋のシミュレート
|
ユーザー |
|
提出日時 | 2018-10-17 22:52:00 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 2,732 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 14,208 KB |
最終ジャッジ日時 | 2024-10-12 18:57:00 |
合計ジャッジ時間 | 4,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
Main.rb:97: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:79: warning: assigned but unused variable - want_toppings_size Syntax OK
ソースコード
class Customer attr_accessor :position # 席番号 attr_accessor :want_toppings # 欲しいネタリスト def initialize(position, toppings) @position, @want_toppings = position, toppings end def eat(topping_name) index = @want_toppings.index(topping_name) unless index.nil? @want_toppings.delete_at(index) return true end false end end class SushiDish attr_accessor :position # 席番号 attr_accessor :topping_name # ネタ名 def initialize(topping_name, position = 1) @topping_name, @position = topping_name, position end # 皿の移動。移動後の席の位置を返す。最後の席の位置にいたら nil を返す def move if @position < ConveyorBeltSushiSystem::SEAT_LENGTH @position += 1 else @position = nil end end end class ConveyorBeltSushiSystem SEAT_LENGTH = 20 attr_accessor :dishes attr_accessor :customers def initialize @dishes = Array.new(self.class::SEAT_LENGTH, nil) @customers = Array.new(self.class::SEAT_LENGTH, nil) end def go_round @customers.each do |customer| @dishes.each do |dish| customer.eat(dish) end end @dishes.each do |dish| dish.move end end end DATA_CUSTOMER = 0 # 客がくる。「[1]席番号、[2]食べたいものリストの要素数、[3]n食べたいもの1、...、[4+n]食べたいものn」 DATA_SUSHI = 1 # 寿司がコンベアに流される。「寿司ネタの名前」 DATA_CHECK = 2 # 客が会計する。「会計する客の席番号」 system = ConveyorBeltSushiSystem.new data_length = gets.to_i data_lines = [] data_length.times do data_lines.push(gets.split) end data_lines.each do |data| data[0] = data[0].to_i if data[0] == DATA_CUSTOMER want_topping_data_starts_at = 3 # データタイプ 0 の食べたいものリストが始まる要素番号 position = data[1].to_i # 客が座る座席番号 want_toppings_size = data[2].to_i want_toppings = [] # 食べたいものリスト (want_topping_data_starts_at..data.size).each do |index| want_toppings.push(data[index]) end customer = Customer.new(position, want_toppings) system.customers[customer.position - 1] = customer elsif data[0] == DATA_SUSHI topping_name = data[1] # 寿司ネタの名前 is_eaten = false system.customers.compact.each do |customer| is_eaten = customer.eat(topping_name) # 客が食べたら次のデータの処理へ if is_eaten puts customer.position break end end puts -1 unless is_eaten elsif data[0] == DATA_CHECK system.customers[data[1].to_i - 1] = nil else raise 'invalid data type.' end end