結果
| 問題 |
No.398 ハーフパイプ(2)
|
| ユーザー |
|
| 提出日時 | 2016-07-15 23:55:57 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 225 ms / 2,000 ms |
| コード長 | 2,261 bytes |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 13,440 KB |
| 最終ジャッジ日時 | 2024-06-27 14:35:34 |
| 合計ジャッジ時間 | 4,749 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
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))