結果

問題 No.1501 酔歩
ユーザー lam6er
提出日時 2025-03-20 20:51:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,122 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 114,568 KB
最終ジャッジ日時 2025-03-20 20:52:19
合計ジャッジ時間 18,873 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from fractions import Fraction

def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    
    if K == 1:
        print("0")
        return
    if K == N:
        print("1/1")
        return
    
    # We compute C[j] for j from 2 to N-1 (inclusive)
    C = {}
    for j in range(2, N):
        # For the j-th position in the problem (1-based)
        # A_{j-1} is A[j-2] (0-based), A_{j+1} is A[j] (0-based)
        denominator = A[j-2] + A[j]
        a_numerator = A[j-2]
        b_numerator = A[j]
        a = Fraction(a_numerator, denominator)
        b = Fraction(b_numerator, denominator)
        
        if j == 2:
            C[j] = b
        else:
            prev_C = C[j-1]
            denominator_C = 1 - a * prev_C
            C[j] = b / denominator_C
    
    # Calculate the product from K to N-1
    result = Fraction(1, 1)
    for j in range(K, N):
        result *= C[j]
    
    if result.numerator == 0:
        print("0")
    else:
        print(f"{result.numerator}/{result.denominator}")

if __name__ == "__main__":
    main()
0