結果
| 問題 |
No.398 ハーフパイプ(2)
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:52:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 147 ms / 2,000 ms |
| コード長 | 3,242 bytes |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 81,648 KB |
| 実行使用メモリ | 77,668 KB |
| 最終ジャッジ日時 | 2025-03-20 20:52:56 |
| 合計ジャッジ時間 | 3,063 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
import math
from math import comb
def main():
x_str = input().strip()
# Split the input into integral and fractional parts
if '.' in x_str:
integral_part, fractional_part = x_str.split('.')
fractional_part = fractional_part.ljust(2, '0')[:2]
else:
integral_part = x_str
fractional_part = '00'
integral = int(integral_part)
fractional = int(fractional_part[:2])
# Calculate S = 4*X as an integer
# X is integral_part + fractional_part/100
# So 4*X = 4*integral_part + (4*fractional_part)/100
# To avoid floating points, we compute S as (4 * (integral * 100 + fractional)) // 100
total = integral * 100 + fractional
S = (4 * total) // 100
ans = 0
# Case 1: All scores are the same (L == H)
if fractional == 0 and 0 <= integral <= 100:
ans += 1 # All six judges give X
# Case 2: L < H
for L in range(0, 100):
for H in range(L + 1, 101):
# Iterate over possible a and b where a >=1, b >=1, a + b <=6
for a in range(1, 6):
max_b = 6 - a
if max_b < 1:
continue
for b in range(1, max_b + 1):
k = 6 - a - b
sum_m = S + L + H - L * a - H * b
if k == 0:
# Check sum_m is 0 and equation (a-1)*L + (5-a)*H == S
if sum_m == 0 and (4 * total) // 100 == (a-1)*L + (5 - a)*H:
# Compute combinations: C(6, a) * C(6-a, b)
c = comb(6, a) * comb(6 - a, b)
ans += c
else:
# Check H - L >= 2, sum_m is within the valid range
if H - L < 2:
continue
lower = k * (L + 1)
upper = k * (H - 1)
if sum_m < lower or sum_m > upper:
continue
# Calculate the number of ways for the intermediate values
D = H - L - 2
Y = sum_m - k * (L + 1)
if Y < 0 or Y > k * D:
continue
# Apply inclusion-exclusion principle
max_t = Y // (D + 1)
current = 0
for t in range(0, max_t + 1):
sign = (-1) ** t
term = comb(k, t)
rem = Y - t * (D + 1)
term *= comb(rem + k - 1, k - 1)
current += sign * term
if current <= 0:
continue
# Add to answer considering all arrangements
c_ab = comb(6, a) * comb(6 - a, b)
ans += c_ab * current
print(ans)
if __name__ == "__main__":
main()
lam6er