結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 MLE -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 MLE -
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 MLE -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,504 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 RE -
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 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 dp = new real[][](n+1, m+1);
  foreach (ref dpi; dp) dpi[] = 0;
  dp[0][0] = 1;
  
  foreach (i; 1..n+1)
    foreach (j; 1..m+1)
      dp[i][j] = dp[i-1][max(0, j-6)..j].sum / 6;

  return dp[n][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