結果

問題 No.302 サイコロで確率問題 (2)
ユーザー te-shte-sh
提出日時 2017-06-15 17:04:50
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2,134 ms / 6,000 ms
コード長 802 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 152,844 KB
実行使用メモリ 6,864 KB
最終ジャッジ日時 2023-09-03 14:27:08
合計ジャッジ時間 9,887 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 796 ms
6,828 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1,405 ms
6,852 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1,617 ms
6,864 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2,134 ms
6,612 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 24 ms
6,856 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 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, m)..min(r, m)+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