結果

問題 No.302 サイコロで確率問題 (2)
ユーザー parukiparuki
提出日時 2016-11-25 13:18:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 6,000 ms
コード長 2,149 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 165,860 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 07:29:09
合計ジャッジ時間 2,707 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

/***
誤差関数
erf(x) = 2/sqrt(PI) *∫(0<=t<=x, e^(-t^2))dt

標準正規分布の確率
P(0<=X<=a)
= ∫(0<=x<=a, 1/sqrt(2*PI)*e^(-x^2/2))dx
= ∫(0<=t<=sqrt(2)/2 * a, 1/sqrt(2*PI)*e^-t^2*sqrt(2))dt
= 1/2 * { 2/sqrt(PI) * ∫(0<=t<=sqrt(2)/2 * a, e^(-t)^2)dt }
= 1/2 * erf(sqrt(2)/2*a)

(x1+x2+...xn)/n
がx 以下
になる確率
***/
double centralLimitTheorem(long long n, double x, double mean, double sd) {
    double y = (x - mean) / sd * sqrt(2.0 * n) / 2;
    double res = 0;
    if(y < 0) res = 0.5 * (1 - erf(-y));
    else res = 0.5 * (1 + erf(y));
    return res;
}

double dp[2][12001];
double f(int N, int L, int R) {
    double p = 1 / 6.0;
    dp[0][0] = 1;
    rep(i, N) {
        int c = i & 1;
        fill_n(dp[!c], (i + 1) * 6 + 1, 0.0);
        rep(j, i * 6 + 1) {
            for(int k = 1; k <= 6; ++k) {
                dp[!c][j + k] += dp[c][j] * p;
            }
        }
    }
    double ans = 0;
    for(int i = L; i <= R; ++i) {
        ans += dp[N&1][i];
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, L, R;
    double m = 3.5;
    double sd = sqrt(35.0 / 12);

    while(cin >> N >> L >> R) {
        smin(L, N * 6);
        smin(R, N * 6);
        smax(L, N);
        if(N > 2000) {
            double l = L ? centralLimitTheorem(N, (double)(L-0.5) / N, m, sd) : 0;
            double r = R ? centralLimitTheorem(N, (double)(R+0.5) / N, m, sd) : 0;
            double ans = r - l;
            cout << setprecision(20) << ans << endl;
        } else {
            cout << setprecision(20) << f(N, L, R) << endl;
        }
    }
}
0