結果
| 問題 |
No.5003 物理好きクリッカー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-02 16:18:42 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 552 ms / 10,000 ms |
| コード長 | 2,243 bytes |
| コンパイル時間 | 32 ms |
| 実行使用メモリ | 27,448 KB |
| スコア | 21,672,124,448 |
| 平均クエリ数 | 10000.00 |
| 最終ジャッジ日時 | 2021-07-19 07:55:08 |
| 合計ジャッジ時間 | 20,271 ms |
|
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
コンパイルメッセージ
Main.rb:68: warning: assigned but unused variable - score Syntax OK
ソースコード
#!/usr/bin/env ruby
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),
]
def solve(special)
cookie = 0
num_buildings = [0] * 5
pow_buildings = [1] * 5
fever_turns = 0
cmds = []
10000.times do |t|
choices = []
5.times do |i|
building = BUILDINGS[i]
nb = num_buildings[i]
pb = pow_buildings[i]
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]
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
cmds << "#{cmd} #{BUILDINGS[bi].name}"
cookie -= 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
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