結果

問題 No.398 ハーフパイプ(2)
ユーザー rpy3cpprpy3cpp
提出日時 2016-07-15 23:55:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 2,261 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 10,944 KB
最終ジャッジ日時 2023-09-09 22:04:13
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 186 ms
10,832 KB
testcase_01 AC 187 ms
10,748 KB
testcase_02 AC 186 ms
10,824 KB
testcase_03 AC 187 ms
10,944 KB
testcase_04 AC 186 ms
10,760 KB
testcase_05 AC 186 ms
10,732 KB
testcase_06 AC 186 ms
10,820 KB
testcase_07 AC 186 ms
10,768 KB
testcase_08 AC 186 ms
10,764 KB
testcase_09 AC 187 ms
10,888 KB
testcase_10 AC 188 ms
10,824 KB
testcase_11 AC 187 ms
10,816 KB
testcase_12 AC 186 ms
10,852 KB
testcase_13 AC 187 ms
10,932 KB
testcase_14 AC 185 ms
10,764 KB
testcase_15 AC 187 ms
10,764 KB
testcase_16 AC 187 ms
10,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import factorial

def init_dp():
    max_n = 4
    max_h = 100
    max_s = 400
    dp = [[[0] * (max_s + 1) for i in range(max_h + 1)] for j in range(max_n + 1)]
    # n = 0
    for h in range(max_h + 1):
        dp[0][h][0] = 1

    # n = 1
    for h in range(max_h + 1):
        dp1h = dp[1][h]
        for s in range(h + 1):
            dp1h[s] = 1
    # n = 2
    for h in range(max_h + 1):
        dp2h = dp[2][h]
        for s in range(h + 1):
            dp2h[s] = s + 1
        for s in range(h + 1, 2 * h + 1):
            dp2h[s] = 2 * h + 1 - s
    
    # n = 3
    for h in range(max_h + 1):
        dp3h = dp[3][h]
        dp2h = dp[2][h]
        for s in range(3 * h + 1):
            dp3h[s] = sum(dp2h[s - i] for i in range(min(h, s) + 1))
    
    # n = 4
    for h in range(max_h + 1):
        dp4h = dp[4][h]
        dp3h = dp[3][h]
        for s in range(4 * h + 1):
            dp4h[s] = sum(dp3h[s - i] for i in range(min(h, s) + 1))
    return dp
        
X = float(input())
dp = init_dp()

def solve(X):
    S = int(X * 4)
    ans = 0
    if S % 4 == 0:
        ans += 1   # 6人全員が同じ点数となるケース
    for n_low in range(1, 6):
        for n_high in range(1, 7 - n_low):
            ans += f(n_low, n_high, S)
    return ans

def f(n_low, n_high, S):
    '''最小値と同じ点数が n_low 人、
    最大値と同じ点数が n_high 人いるときに、
    最大最小を除いた4人の点数の合計が S となるパターンの数。
    最大と最小がすべて同じになるケースは考えないものとする。
    '''
    n_other = 6 - n_low - n_high
    ans = 0
    for low in range(0, 100):
        for high in range(low + 1, 101):
            ans += g(n_other, low + 1, high - 1, S - (n_low - 1) * low - (n_high - 1) * high)
    mul = factorial(6) // factorial(n_low)//factorial(n_high)//factorial(n_other)
    return mul * ans

def g(n, low, high, s):
    ''' n 人のスコアの合計が s となるパターンの数を返す。
    n 人のスコアは、low 点以上、high 点以下とする。
    '''
    if low * n > s or high * n < s:
        return 0
    if low * n == s or high * n == 2:
        return 1
    return dp[n][high - low][s - n * low]

print(solve(X))
0