結果
問題 | No.5003 物理好きクリッカー |
ユーザー | yowa |
提出日時 | 2018-12-07 08:25:56 |
言語 | Ruby (3.4.1) |
結果 |
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 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
Main.rb:100: warning: assigned but unused variable - n Main.rb:104: warning: assigned but unused variable - score Syntax OK
ソースコード
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