結果

問題 No.302 サイコロで確率問題 (2)
ユーザー 0w10w1
提出日時 2017-12-30 22:56:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,185 ms / 6,000 ms
コード長 1,058 bytes
コンパイル時間 2,100 ms
コンパイル使用メモリ 203,988 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 11:10:33
合計ジャッジ時間 5,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
4,376 KB
testcase_01 AC 1,185 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 104 ms
4,380 KB
testcase_04 AC 1,182 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 119 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 156 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

double naive_solve(long long n, long long l, long long r) {
  l = std::min(6 * n, std::max(n, l));
  r = std::min(6 * n, r);
  std::vector<std::vector<double>> dp(2, std::vector<double>(n * 6 + 1));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    std::fill(dp[~i & 1].begin(), dp[~i & 1].end(), 0);
    for (int j = i; j <= 6 * i; ++j) {
      for (int d = 1; d <= 6; ++d) {
        dp[~i & 1][j + d] += dp[i & 1][j] / 6;
      }
    }
  }
  return std::accumulate(dp[n & 1].begin() + l, dp[n & 1].begin() + r + 1, 0.0);
}

double extreme_solve(long long n, long long l, long long r) {
  double avg = n * 3.5;
  double var = n * 35 / 12;
  return (std::erf((r + 0.5 - avg) / std::sqrt(2 * var)) - std::erf((l - 0.5 - avg) / std::sqrt(2 * var))) / 2;
}

signed main() {
  long long N, L, R;
  std::cin >> N >> L >> R;
  if (N < 8000) std::cout << std::fixed << std::setprecision(6) << naive_solve(N, L, R) << std::endl;
  else std::cout << std::fixed << std::setprecision(6) << extreme_solve(N, L, R) << std::endl;
  return 0;
}
0