結果

問題 No.5003 物理好きクリッカー
ユーザー Shinichiro HamajiShinichiro Hamaji
提出日時 2018-12-02 18:26:02
言語 Ruby
(3.3.0)
結果
AC  
実行時間 553 ms / 10,000 ms
コード長 2,440 bytes
コンパイル時間 79 ms
実行使用メモリ 27,300 KB
スコア 194,947,182,268
平均クエリ数 10000.00
最終ジャッジ日時 2021-07-19 07:54:47
合計ジャッジ時間 20,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 532 ms
27,096 KB
testcase_01 AC 527 ms
26,932 KB
testcase_02 AC 528 ms
26,832 KB
testcase_03 AC 529 ms
27,100 KB
testcase_04 AC 532 ms
27,120 KB
testcase_05 AC 529 ms
27,036 KB
testcase_06 AC 540 ms
27,180 KB
testcase_07 AC 535 ms
27,160 KB
testcase_08 AC 538 ms
26,744 KB
testcase_09 AC 528 ms
26,924 KB
testcase_10 AC 527 ms
27,116 KB
testcase_11 AC 535 ms
27,060 KB
testcase_12 AC 526 ms
26,932 KB
testcase_13 AC 522 ms
27,028 KB
testcase_14 AC 522 ms
27,032 KB
testcase_15 AC 528 ms
26,988 KB
testcase_16 AC 529 ms
26,952 KB
testcase_17 AC 536 ms
27,096 KB
testcase_18 AC 531 ms
26,904 KB
testcase_19 AC 530 ms
26,972 KB
testcase_20 AC 534 ms
27,100 KB
testcase_21 AC 527 ms
27,048 KB
testcase_22 AC 530 ms
26,880 KB
testcase_23 AC 534 ms
26,860 KB
testcase_24 AC 526 ms
26,660 KB
testcase_25 AC 526 ms
26,888 KB
testcase_26 AC 531 ms
27,000 KB
testcase_27 AC 553 ms
26,816 KB
testcase_28 AC 530 ms
26,892 KB
testcase_29 AC 528 ms
27,180 KB
testcase_30 AC 533 ms
27,104 KB
testcase_31 AC 530 ms
27,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:74: warning: assigned but unused variable - score
Syntax OK

ソースコード

diff #

#!/usr/bin/env ruby

srand 10

def gen_special
  special = ''
  i = rand(200)
  while special.size < 10000
    special += 'N' * i
    special += 'BFS'[rand(3)]
    i = rand(100) + 100
  end
  special[0,10000]
end

class Building
  attr_accessor :name, :cps

  def initialize(name, cps, price)
    @name = name
    @cps = cps
    @price = price
  end

  def price(n)
    r = @price * (6 ** n)
    m = 5 ** n
    (r + m - 1) / m
  end

  def rprice(n, pow)
    @price * 10 ** pow
  end

end

BUILDINGS = [
  Building.new('hand', 1, 150),
  Building.new('lily', 10, 2000),
  Building.new('factory', 120, 30000),
  Building.new('casino', 2000, 600000),
  Building.new('grimoire', 25000, 10000000),
  Building.new('click', 0.5, 15),
]

def solve(special)
  cookie = 0
  num_buildings = [0] * 5 + [1]
  pow_buildings = [1] * 6
  fever_turns = 0
  spent = 0
  cmds = []

  10000.times do |t|
    choices = []
    5.times do |i|
      building = BUILDINGS[i]
      nb = num_buildings[i]
      pb = pow_buildings[i]

      if building.name != 'click'
        pr = building.price(nb)
        cps_per_price = building.cps.to_f * pb / pr
        score = cps_per_price / Math.log(pr)
        choices << [score, pr, "buy", i]
      end

      pr = building.rprice(nb, pb)
      cps_per_price = building.cps.to_f * pb * nb / pr
      score = cps_per_price / Math.log(pr)
      choices << [score, pr, "reinforce", i]
    end

    score, pr, cmd, bi = choices.sort[-1]
    #STDERR.puts "#{cmd} #{bi}"
    if pr <= cookie && t < 8000
      cmds << "#{cmd} #{BUILDINGS[bi].name}"
      cookie -= pr
      spent += pr
      if cmd == "buy"
        num_buildings[bi] += 1
      elsif cmd == "reinforce"
        pow_buildings[bi] *= 2
      else
        raise
      end
    else
      cmds << "click"
      cookie += 1
    end

    in_fever = fever_turns > 0 ? 7 : 1
    fever_turns -= 1
    5.times do |i|
      building = BUILDINGS[i]
      cookie += building.cps * pow_buildings[i] * num_buildings[i] * in_fever
    end

    case special[t]
    when 'B'
      cookie += (cookie + 99) / 100
    when 'F'
      fever_turns = 20
    when 'S'
    end
  end

  STDERR.puts "#{cookie} #{spent} #{cookie * 100.0 / (spent + cookie)}%"

  cmds
end

if ARGV[0] == '--test'
  solve(gen_special)
else
  gets
  special = gets.chomp
  cmds = solve(special)
  10000.times do |t|
    puts cmds[t]
    STDOUT.flush
    ans = gets.chomp
    raise ans if ans != 'ok'
  end
end

0