結果

問題 No.302 サイコロで確率問題 (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-11-13 23:19:23
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 72,172 KB
最終ジャッジ日時 2023-10-11 16:34:21
合計ジャッジ時間 3,336 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 98 ms
71,948 KB
testcase_02 AC 95 ms
71,820 KB
testcase_03 WA -
testcase_04 AC 97 ms
72,172 KB
testcase_05 AC 98 ms
71,852 KB
testcase_06 AC 100 ms
71,872 KB
testcase_07 AC 97 ms
71,980 KB
testcase_08 AC 96 ms
71,896 KB
testcase_09 AC 97 ms
72,004 KB
testcase_10 AC 96 ms
71,752 KB
testcase_11 AC 98 ms
71,496 KB
testcase_12 AC 96 ms
71,592 KB
testcase_13 AC 97 ms
71,504 KB
testcase_14 AC 97 ms
71,644 KB
testcase_15 AC 99 ms
71,520 KB
testcase_16 AC 97 ms
71,416 KB
testcase_17 AC 95 ms
71,940 KB
testcase_18 AC 96 ms
71,680 KB
testcase_19 AC 96 ms
71,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import math

def solve(N, L, R):
    if N < 300:
        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
    r = (R + 0.5 - E)/math.sqrt(Var)
    l = (L - 0.5 - E)/math.sqrt(Var)
    return phi(r) - phi(l)
                

def phi(x):
    return (1.0 + math.erf(x / math.sqrt(2.0))) / 2.0

N = int(input())
L, R = map(int, input().split())
print(solve(N, L, R))
0