結果

問題 No.5003 物理好きクリッカー
ユーザー yowayowa
提出日時 2018-12-07 08:25:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 391 ms / 10,000 ms
コード長 2,053 bytes
コンパイル時間 106 ms
実行使用メモリ 26,996 KB
スコア 5,577,940
平均クエリ数 10000.00
最終ジャッジ日時 2021-07-19 09:02:38
合計ジャッジ時間 14,807 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 366 ms
26,528 KB
testcase_01 AC 353 ms
26,560 KB
testcase_02 AC 366 ms
26,732 KB
testcase_03 AC 353 ms
26,776 KB
testcase_04 AC 353 ms
26,740 KB
testcase_05 AC 367 ms
26,780 KB
testcase_06 AC 349 ms
26,576 KB
testcase_07 AC 353 ms
26,588 KB
testcase_08 AC 382 ms
26,768 KB
testcase_09 AC 380 ms
26,748 KB
testcase_10 AC 375 ms
26,596 KB
testcase_11 AC 356 ms
26,728 KB
testcase_12 AC 359 ms
26,576 KB
testcase_13 AC 367 ms
26,672 KB
testcase_14 AC 358 ms
26,620 KB
testcase_15 AC 357 ms
26,516 KB
testcase_16 AC 355 ms
26,572 KB
testcase_17 AC 379 ms
26,584 KB
testcase_18 AC 351 ms
26,760 KB
testcase_19 AC 362 ms
26,536 KB
testcase_20 AC 355 ms
26,448 KB
testcase_21 AC 390 ms
26,476 KB
testcase_22 AC 391 ms
26,944 KB
testcase_23 AC 349 ms
26,528 KB
testcase_24 AC 386 ms
26,884 KB
testcase_25 AC 352 ms
26,800 KB
testcase_26 AC 351 ms
26,468 KB
testcase_27 AC 353 ms
26,792 KB
testcase_28 AC 350 ms
26,536 KB
testcase_29 AC 371 ms
26,648 KB
testcase_30 AC 346 ms
26,708 KB
testcase_31 AC 350 ms
26,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:100: warning: assigned but unused variable - n
Main.rb:104: warning: assigned but unused variable - score
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
score = cl.run(s)
#$stderr.puts score
cl.instance_eval{@history}.each do |cmd|
  puts cmd
  $stdout.flush
  gets
end
0