結果

問題 No.58 イカサマなサイコロ
ユーザー tktk_snsn
提出日時 2020-06-03 23:07:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-11-26 08:21:10
合計ジャッジ時間 1,230 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
from collections import defaultdict

N = int(input())
K = int(input())
U = 6 * N + 1
p1 = 1 / 3
p2 = 1 / 6
val1 = [4, 5, 6]
prob1 = [p1] * 3
val2 = [1, 2, 3, 4, 5, 6]
prob2 = [p2] * 6

# taro
taro = [0] * U
taro[0] = 1
for _ in range(K):
    newDP = [0] * U
    for v, p in zip(val1, prob1):
        for i in range(v, U):
            newDP[i] += taro[i - v] * p
    taro = newDP
for _ in range(N - K):
    newDP = [0] * U
    for v, p in zip(val2, prob2):
        for i in range(v, U):
            newDP[i] += taro[i - v] * p
    taro = newDP

# jiro
jiro = [0] * U
jiro[0] = 1
for _ in range(N):
    newDP = [0] * U
    for v, p in zip(val2, prob2):
        for i in range(v, U):
            newDP[i] += jiro[i - v] * p
    jiro = newDP

jiro.reverse()
jiro_acc = list(accumulate(jiro))
jiro_acc.reverse()

ans = sum(t*(1-j) for t, j in zip(taro, jiro_acc))

print(ans)
0