結果

問題 No.425 ジャンケンの必勝法
コンテスト
ユーザー nebukuro09
提出日時 2016-11-12 10:19:05
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 1 ms / 2,000 ms
+ 85µs
コード長 757 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,326 ms
コンパイル使用メモリ 133,504 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-25 23:51:27
合計ジャッジ時間 2,816 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;
import std.numeric;

double[Tuple!(int, int)] mem;
int P_init, Q;

double rec(int p, int depth){
  if (depth >= 20)
    return 1.0;
  if (tuple(p, depth) in mem)
    return mem[tuple(p, depth)];

  mem[tuple(p, depth)] = p / 200.0 + (100-p) / 300.0
                       + p / 200.0 * rec(max(p-Q, 0), depth+1)
                       + (100-p) / 300.0 * rec(min(p+Q, 100), depth+1);
  
  return mem[tuple(p, depth)];
}

void main() {
  auto input = readln.split.map!(to!int);
  P_init = input[0];
  Q = input[1];

  writef("%.07f", 1.0/3 + rec(P_init, 0) / 3.0);
}
0