結果
| 問題 |
No.425 ジャンケンの必勝法
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-23 10:49:13 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 484 bytes |
| コンパイル時間 | 50 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 14,080 KB |
| 最終ジャッジ日時 | 2024-12-26 06:41:09 |
| 合計ジャッジ時間 | 3,335 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 18 |
コンパイルメッセージ
Syntax OK
ソースコード
@pz,@q = gets.split.map{|e|e.to_f/100.0}
@memo={}
def calc(pi,deep)
pi = pi<0 ? 0.0 : 1<pi ? 1.0 : pi
key = [pi,deep] # <---bugfix!!
return @memo[key] if @memo[key]
return 1.0 if deep>200
r = 0.0
#used
r += (1.0 + calc(pi-@q,deep+1)) /2.0 * (pi) if pi >0.0
#unused
r += (1.0 + calc(pi+@q,deep+1)) /3.0 * (1.0-pi) if pi <1.0
return @memo[key] = r
end
result = (1.0 + calc(@pz,0)) / 3.0
p result.to_f