結果

問題 No.302 サイコロで確率問題 (2)
ユーザー rpy3cpprpy3cpp
提出日時 2015-11-13 23:51:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,261 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 72,432 KB
最終ジャッジ日時 2023-10-11 17:06:09
合計ジャッジ時間 3,442 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 95 ms
71,856 KB
testcase_02 AC 95 ms
71,452 KB
testcase_03 WA -
testcase_04 AC 93 ms
71,820 KB
testcase_05 AC 95 ms
71,744 KB
testcase_06 AC 93 ms
71,776 KB
testcase_07 AC 93 ms
71,692 KB
testcase_08 AC 96 ms
71,788 KB
testcase_09 AC 95 ms
71,792 KB
testcase_10 AC 97 ms
71,600 KB
testcase_11 AC 96 ms
71,340 KB
testcase_12 AC 99 ms
71,188 KB
testcase_13 AC 98 ms
71,472 KB
testcase_14 AC 98 ms
71,600 KB
testcase_15 AC 97 ms
71,400 KB
testcase_16 AC 98 ms
71,448 KB
testcase_17 AC 97 ms
71,676 KB
testcase_18 AC 98 ms
71,548 KB
testcase_19 AC 94 ms
71,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import math

def solve(N, L, R):
    if R < N:
        return 0
    if L > 6 * N:
        return 0
    if L < N and R > 6 * N:
        return 1
    if N < 100:
        return solve_exact(N, L, R)
    else:
        return solve_approximate(N, L, R)

def solve_exact(N, L, R):
    fs = {0: 1}
    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
        fs = nfs
    cum = 0
    for v, p in fs.items():
        if L <= v and v <= R:
            cum += p
    return cum/(6**N)


def solve_approximate(N, L, R):
    E = N * 3.5
    Var = N * 35.0/12.0
    if R >= N * 6:
        pR = 0.5
    elif R < N:
        pR = -0.5
    else:
        pR = (math.erf((R + 0.5 - E)/math.sqrt(2 * Var))) / 2.0
    if L >= N * 6:
        pL = 0.5
    elif L < N:
        pL = -0.5
    else:       
        pL = (math.erf((L - 0.5 - E)/math.sqrt(2 * Var))) / 2.0
    return pR - pL
                

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('{:f}'.format(solve(N, L, R)))
0