結果

問題 No.162 8020運動
ユーザー te-shte-sh
提出日時 2017-04-28 17:31:10
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,045 ms / 5,000 ms
コード長 1,197 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 155,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 13:06:32
合計ジャッジ時間 21,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,376 KB
testcase_01 AC 374 ms
4,380 KB
testcase_02 AC 668 ms
4,376 KB
testcase_03 AC 1,041 ms
4,380 KB
testcase_04 AC 1,036 ms
4,376 KB
testcase_05 AC 1,038 ms
4,380 KB
testcase_06 AC 1,034 ms
4,376 KB
testcase_07 AC 1,035 ms
4,376 KB
testcase_08 AC 1,045 ms
4,376 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 670 ms
4,376 KB
testcase_11 AC 370 ms
4,376 KB
testcase_12 AC 142 ms
4,376 KB
testcase_13 AC 1,043 ms
4,380 KB
testcase_14 AC 42 ms
4,380 KB
testcase_15 AC 42 ms
4,376 KB
testcase_16 AC 181 ms
4,380 KB
testcase_17 AC 72 ms
4,376 KB
testcase_18 AC 960 ms
4,380 KB
testcase_19 AC 603 ms
4,376 KB
testcase_20 AC 735 ms
4,376 KB
testcase_21 AC 737 ms
4,380 KB
testcase_22 AC 664 ms
4,376 KB
testcase_23 AC 733 ms
4,376 KB
testcase_24 AC 666 ms
4,376 KB
testcase_25 AC 801 ms
4,380 KB
testcase_26 AC 16 ms
4,380 KB
testcase_27 AC 420 ms
4,380 KB
testcase_28 AC 954 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;      // math functions

void main()
{
  auto a = 80 - readln.chomp.to!int;
  auto rd = readln.split.map!(s => s.to!real / 100).array, p0 = rd[0], p1 = rd[1], p2 = rd[2];

  auto dp = new real[][](a + 1, 15);

  real prob(ulong b, int n)
  {
    real r = 1;
    r *= b.bitTest(0)   ? 1 - p1 : p1;
    r *= b.bitTest(n-1) ? 1 - p1 : p1;
    foreach (i; 1..n-1)
      r *= b.bitTest(i) ? 1 - p2 : p2;
    return r;
  }

  int[] conts(ulong b, int n)
  {
    auto r = new int[](0), c = 0;
    foreach (i; 0..n) {
      if (b.bitTest(i)) {
        ++c;
      } else if (c) {
        r ~= c; c = 0;
      }
    }
    if (c) r ~= c;
    return r;
  }

  real calc(int y, int n)
  {
    if (y == 0) return n;
    if (n == 1) return (1 - p0) * calc(y - 1, n);
    if (!dp[y][n].isNaN) return dp[y][n];

    real e = 0;
    foreach (i; 0..(1 << n)) {
      auto p = prob(i, n);
      auto ci = conts(i, n);
      e += p * ci.map!(c => calc(y - 1, c)).sum;
    }
    return dp[y][n] = e;
  }

  writefln("%.7f", calc(a, 14) * 2);
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
}
0