結果

問題 No.5003 物理好きクリッカー
ユーザー yowayowa
提出日時 2018-12-06 22:44:29
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,978 bytes
コンパイル時間 216 ms
実行使用メモリ 26,976 KB
スコア 1,899,032
平均クエリ数 10000.00
最終ジャッジ日時 2021-07-19 09:00:06
合計ジャッジ時間 4,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 57 ms
26,536 KB
testcase_04 WA -
testcase_05 AC 56 ms
26,584 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 62 ms
26,404 KB
testcase_09 AC 57 ms
26,612 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 59 ms
26,920 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 60 ms
26,556 KB
testcase_20 AC 58 ms
26,540 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 56 ms
26,780 KB
testcase_25 AC 60 ms
26,876 KB
testcase_26 AC 61 ms
26,772 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:100: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

class Facility
  def initialize(val, price, num=0)
    @val = val
    @reinforce_price = price
    @price = price
    @num = num || 0
  end

  def produce
    @num * @val
  end

  def reinforce(cookie)
    diff = 0
    if cookie >= @reinforce_price
      diff = -@reinforce_price
      @reinforce_price *= 10
      @val *= 2
    end
    diff
  end
end

class Clicker
  def initialize
    @cookie = 0
    @facilities = {}
    @history = []
    @click = Facility.new(1, 15, 1)
    [
      [:hand, 1, 150],
      [:lily, 10, 2000],
      [:factory, 120, 30000],
      [:casino, 2000, 600000],
      [:grimoire, 25000, 10000000]
    ].each do |name, sp, price|
      @facilities[name] = Facility.new(sp, price)
    end
  end

  def do_action(cmd)
    @history << cmd
    
    case cmd
    when 'click'
      @cookie += @click.produce
    when /\Abuy (.*?)\z/
      name = $1.to_sym
      @cookie += @facilities[name].buy(@cookie)
    when /\Asell (.*?)\z/
      name = $1.to_sym
      @cookie += @facilities[name].sell(@cookie)
    when /\Areinforce (.*?)\z/
      name = $1.to_sym
      @cookie += @facilities[name].reinforce(@cookie)
    when 'enhclick'
      @cookie += @click.reinforce(@cookie)
    when 'nothing'
    # do nothing
    else
      raise "Unknown action: '#{cmd}'"
    end
  end

  def do_produce()
    @facilities.each do |name, f|
      @cookie += f.produce
    end
  end

  def do_special(type)
    if type == 'B' # Bonus
      @cookie += (@cookie+99)/100
      
    elsif type == 'F'# Fever
    elsif type == 'S' # Sale
    elsif type == 'N' # Nothing
      # do nothing
    else
      raise
    end
  end

  def run(s)
    s.each_char.with_index do |ch, turn|
      if @cookie >= @click.instance_eval{@reinforce_price}
        do_action("enhclick")
      else
        do_action("click")
      end
      do_produce()
      do_special(ch)
    end

    @cookie
  end
end


n = gets.to_i
s = gets.chomp

cl = Clicker.new
cl.run(s)
puts cl.instance_eval{@history}
0