結果

問題 No.1501 酔歩
ユーザー to-omerto-omer
提出日時 2021-05-07 23:55:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 147,972 KB
最終ジャッジ日時 2023-10-13 16:02:57
合計ジャッジ時間 30,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 195 ms
89,560 KB
testcase_01 AC 198 ms
89,592 KB
testcase_02 AC 196 ms
89,268 KB
testcase_03 AC 192 ms
89,336 KB
testcase_04 AC 196 ms
89,400 KB
testcase_05 AC 589 ms
134,128 KB
testcase_06 AC 514 ms
123,220 KB
testcase_07 AC 575 ms
132,180 KB
testcase_08 AC 344 ms
100,348 KB
testcase_09 AC 529 ms
126,660 KB
testcase_10 AC 376 ms
105,204 KB
testcase_11 AC 503 ms
123,564 KB
testcase_12 AC 442 ms
113,996 KB
testcase_13 AC 196 ms
89,672 KB
testcase_14 AC 204 ms
89,376 KB
testcase_15 AC 200 ms
89,580 KB
testcase_16 AC 193 ms
89,380 KB
testcase_17 AC 193 ms
89,620 KB
testcase_18 AC 196 ms
89,540 KB
testcase_19 AC 194 ms
89,528 KB
testcase_20 AC 192 ms
89,292 KB
testcase_21 AC 195 ms
89,664 KB
testcase_22 AC 680 ms
147,324 KB
testcase_23 AC 660 ms
147,872 KB
testcase_24 AC 706 ms
147,316 KB
testcase_25 AC 711 ms
147,556 KB
testcase_26 AC 665 ms
146,856 KB
testcase_27 AC 659 ms
147,428 KB
testcase_28 AC 653 ms
147,972 KB
testcase_29 AC 671 ms
147,440 KB
testcase_30 AC 666 ms
146,892 KB
testcase_31 AC 672 ms
147,336 KB
testcase_32 AC 667 ms
147,092 KB
testcase_33 AC 689 ms
147,428 KB
testcase_34 AC 701 ms
147,388 KB
testcase_35 AC 681 ms
147,368 KB
testcase_36 AC 697 ms
147,256 KB
testcase_37 AC 708 ms
147,544 KB
testcase_38 AC 676 ms
147,432 KB
testcase_39 AC 692 ms
147,844 KB
testcase_40 AC 693 ms
147,844 KB
testcase_41 AC 667 ms
147,560 KB
testcase_42 AC 625 ms
146,244 KB
testcase_43 AC 205 ms
89,424 KB
testcase_44 AC 200 ms
89,552 KB
testcase_45 AC 586 ms
145,740 KB
testcase_46 AC 578 ms
145,780 KB
testcase_47 AC 575 ms
146,108 KB
testcase_48 AC 612 ms
146,784 KB
testcase_49 AC 622 ms
146,980 KB
testcase_50 AC 627 ms
147,116 KB
testcase_51 AC 615 ms
147,252 KB
testcase_52 AC 615 ms
147,356 KB
testcase_53 AC 199 ms
89,556 KB
testcase_54 AC 190 ms
89,364 KB
testcase_55 AC 194 ms
89,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from fractions import Fraction as F
def main():
    N,K=map(int, input().split())
    *A,=map(F, input().split())
    if K == N:
        print('1/1')
    elif K == 1:
        print('0')
    else:
        D=[(F(0),F(0))]
        for i in range(1,N-1):
            b = A[i-1]/(A[i-1]+A[i+1])
            a = A[i+1]/(A[i-1]+A[i+1])
            bb, aa = D[-1]
            de = F(1) - b*aa
            nb = b * bb / de
            na = a / de
            D.append((nb, na))
        X = [F(0)] * N
        X[N-1] = F(1)
        for i in range(N-2, 0, -1):
            b, a = D[i]
            X[i] = b + a * X[i+1]
        print(f'{X[K-1].numerator}/{X[K-1].denominator}')

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