結果

問題 No.75 回数の期待値の問題
ユーザー terasa
提出日時 2022-11-22 22:04:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 5,000 ms
コード長 736 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 72,784 KB
最終ジャッジ日時 2024-09-23 05:50:53
合計ジャッジ時間 2,366 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

from typing import List, Tuple, Callable, TypeVar
import sys
import itertools
import heapq
import bisect
import math
from collections import deque, defaultdict, Counter
from functools import lru_cache, cmp_to_key

input = sys.stdin.readline

if __file__ != 'prog.py':
    sys.setrecursionlimit(10 ** 6)


def readints(): return map(int, input().split())
def readlist(): return list(readints())
def readstr(): return input()[:-1]


K = int(input())


@lru_cache(None)
def solve(n):
    if n == K:
        return (0, 0)
    if n > K:
        return (1, 0)

    Sa = 0
    Sb = 0
    for i in range(1, 6 + 1):
        a, b = solve(n + i)
        Sa += a
        Sb += b
    return (Sa / 6, Sb / 6 + 1)


a, b = solve(0)
print(b / (1 - a))
0