結果

問題 No.302 サイコロで確率問題 (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-11-13 23:26:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-11 16:42:17
合計ジャッジ時間 1,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import collections
import math

def solve(N, L, R):
    if N < 1000:
        return solve_exact(N, L, R)
    else:
        return solve_approximate(N, L, R)

def solve_exact(N, L, R):
    fs = {0: 1.0}
    for n in range(N-1, -1, -1):
        nfs = collections.defaultdict(float)
        for v, p in fs.items():
            for dice in range(1, 7):
                nv = v + dice
                if nv + n <= R and nv + n * 6 >= L:
                    nfs[nv] += p * 1/6
        fs = nfs
    cum = 0.0
    for v, p in fs.items():
        if L <= v and v <= R:
            cum += p
    return cum


def solve_approximate(N, L, R):
    E = N * 3.5
    Var = N * 35.0/12.0
    if R >= N * 6:
        pR = 1
    else:
        r = (R + 0.5 - E)/math.sqrt(Var)
        pR = phi(r)
    if L >= N * 6:
        pL = 1
    elif L == 0:
        pL = 0
    else:       
        l = (L - 0.5 - E)/math.sqrt(Var)
        pL = phi(l)
    return pR - pL
0