結果

問題 No.162 8020運動
ユーザー maspymaspy
提出日時 2020-04-09 00:41:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 840 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 9,276 KB
最終ジャッジ日時 2023-09-26 11:17:12
合計ジャッジ時間 2,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,696 KB
testcase_01 AC 22 ms
8,752 KB
testcase_02 AC 23 ms
9,112 KB
testcase_03 AC 24 ms
9,228 KB
testcase_04 AC 23 ms
9,080 KB
testcase_05 AC 23 ms
9,176 KB
testcase_06 AC 23 ms
9,092 KB
testcase_07 AC 23 ms
9,092 KB
testcase_08 AC 23 ms
9,068 KB
testcase_09 AC 19 ms
8,672 KB
testcase_10 AC 22 ms
8,960 KB
testcase_11 AC 22 ms
8,900 KB
testcase_12 AC 20 ms
8,644 KB
testcase_13 AC 25 ms
9,276 KB
testcase_14 AC 20 ms
8,640 KB
testcase_15 AC 21 ms
8,768 KB
testcase_16 AC 21 ms
8,876 KB
testcase_17 AC 20 ms
8,600 KB
testcase_18 AC 23 ms
9,096 KB
testcase_19 AC 23 ms
8,972 KB
testcase_20 AC 23 ms
9,044 KB
testcase_21 AC 23 ms
8,992 KB
testcase_22 AC 23 ms
8,948 KB
testcase_23 AC 22 ms
9,120 KB
testcase_24 AC 22 ms
9,068 KB
testcase_25 AC 22 ms
9,008 KB
testcase_26 AC 19 ms
8,552 KB
testcase_27 AC 21 ms
8,896 KB
testcase_28 AC 23 ms
9,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from functools import lru_cache

A, *P = map(int, read().split())
P = tuple(x / 100 for x in P)

@lru_cache(None)
def f(N, i, rest_year, left_flag=False):
    """ N 本の歯があり、i-1番の歯まで虫判定を終えた"""
    if N == 0:
        return 0
    if rest_year == 0:
        return N
    if i == N:
        return f(N, 0, rest_year - 1)
    p = P[0] if N == 1 else P[1] if i in (0, N - 1) else P[2]
    if i == 0 and left_flag:
        p = P[1] if i == N-1 else P[2]
    # 抜く場合
    x = f(i, 0, rest_year - 1) + f(N - i - 1, 0, rest_year, True)
    # 抜かない場合
    y = f(N, i + 1, rest_year)
    return p * x + (1 - p) * y


answer = f(14, 0, 80 - A) * 2
print(answer)
0