結果
| 問題 |
No.813 ユキちゃんの冒険
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:39:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,272 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 81,840 KB |
| 実行使用メモリ | 54,352 KB |
| 最終ジャッジ日時 | 2025-06-12 21:43:52 |
| 合計ジャッジ時間 | 2,126 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 26 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
N = int(input[0])
p = float(input[1])
q = float(input[2])
if N == 0:
print(1.0)
return
# Handle special cases where division by zero might occur
if 1 - p == 0:
if q == 0:
print(1.0)
return
else:
print(0.0)
return
# Compute c_i using the recurrence
c = [0.0] * (N + 1)
c[0] = q / (1 - p)
c[1] = 1.0
for i in range(2, N + 1):
if q == 0:
if c[i-1] - p * c[i-2] == 0:
c[i] = 0.0
else:
c[i] = float('inf') # Handle division by zero
else:
c[i] = (c[i-1] - p * c[i-2]) / q
# Check if c_N == p * c_{N-1}
if abs(c[N] - p * c[N-1]) < 1e-10:
f1 = 1.0 # Arbitrary since condition holds
else:
# Compute the required factor to satisfy the condition
numerator = p * c[N-2] - (1 - p * q) * c[N-1]
denominator = (1 - p * q) * c[N-1] - p * c[N-2]
if denominator == 0:
f1 = 0.0
else:
f1 = numerator / denominator
# Compute f0
f0 = q * f1 / (1 - p)
print("{0:.12f}".format(f0))
if __name__ == "__main__":
main()
gew1fw