結果

問題 No.302 サイコロで確率問題 (2)
ユーザー te-shte-sh
提出日時 2017-06-15 17:03:34
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 802 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 152,764 KB
実行使用メモリ 7,272 KB
最終ジャッジ日時 2023-09-03 14:26:42
合計ジャッジ時間 9,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 769 ms
6,800 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,500 KB
testcase_03 AC 1,358 ms
6,864 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1,557 ms
6,860 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2,053 ms
6,544 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;
import std.mathspecial;

// allowable-error: 10 ** -5

void main()
{
  auto n = readln.chomp.to!long;
  auto rd = readln.split.to!(long[]), l = rd[0], r = rd[1];

  writefln("%.6f", n < 5000 ? calc1(n, l, r) : calc2(n, l, r));
}

auto calc1(long n, long l, long r)
{
  auto m = n * 6;

  auto dp1 = new real[](m+1);
  dp1[0] = 1; dp1[1..$] = 0;
  
  foreach (i; 1..n+1) {
    auto dp2 = new real[](m+1);
    dp2[] = 0;

    foreach (j; 1..m+1)
      dp2[j] = dp1[max(0, j-6)..j].sum / 6;

    dp1 = dp2;
  }

  return dp1[min(l, r)..min(m, r)+1].sum;
}

auto calc2(long n, long l, long r)
{
  auto u = 7.0 / 2 * n, s2 = 35.0 / 12 * n;
  return (erf((r+0.5 - u) / sqrt(s2 * 2)) - erf((l-0.5 - u) / sqrt(s2 * 2))) / 2;
}
0