結果

問題 No.1501 酔歩
ユーザー kimiyukikimiyuki
提出日時 2021-05-07 22:20:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,080 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 30,872 KB
最終ジャッジ日時 2023-10-13 13:35:42
合計ジャッジ時間 66,847 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,460 KB
testcase_01 AC 36 ms
10,372 KB
testcase_02 AC 35 ms
10,344 KB
testcase_03 AC 36 ms
10,352 KB
testcase_04 RE -
testcase_05 AC 1,595 ms
26,484 KB
testcase_06 AC 1,190 ms
22,172 KB
testcase_07 AC 1,520 ms
25,276 KB
testcase_08 AC 340 ms
13,636 KB
testcase_09 AC 1,375 ms
23,592 KB
testcase_10 AC 507 ms
15,388 KB
testcase_11 AC 1,231 ms
22,188 KB
testcase_12 AC 767 ms
18,936 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 1,928 ms
30,776 KB
testcase_23 TLE -
testcase_24 AC 1,956 ms
30,580 KB
testcase_25 AC 1,905 ms
30,872 KB
testcase_26 AC 1,794 ms
30,508 KB
testcase_27 AC 1,946 ms
30,800 KB
testcase_28 TLE -
testcase_29 AC 1,856 ms
30,680 KB
testcase_30 TLE -
testcase_31 AC 1,855 ms
30,564 KB
testcase_32 AC 1,859 ms
30,652 KB
testcase_33 TLE -
testcase_34 AC 1,961 ms
30,680 KB
testcase_35 AC 1,913 ms
30,660 KB
testcase_36 AC 1,973 ms
30,588 KB
testcase_37 AC 1,791 ms
30,668 KB
testcase_38 AC 1,847 ms
30,700 KB
testcase_39 TLE -
testcase_40 AC 1,889 ms
30,608 KB
testcase_41 TLE -
testcase_42 AC 1,703 ms
28,404 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 AC 1,820 ms
28,004 KB
testcase_46 AC 1,946 ms
27,996 KB
testcase_47 AC 1,644 ms
28,100 KB
testcase_48 AC 1,719 ms
28,268 KB
testcase_49 AC 1,903 ms
28,396 KB
testcase_50 AC 1,824 ms
28,364 KB
testcase_51 AC 1,719 ms
28,188 KB
testcase_52 AC 1,698 ms
28,412 KB
testcase_53 RE -
testcase_54 AC 35 ms
10,460 KB
testcase_55 AC 36 ms
10,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import fractions
from typing import *


def solve(n: int, k: int, x: List[int]) -> str:
    a = [None] * (n - 1)
    b = [None] * (n - 1)
    a[0] = 0
    b[0] = 0
    for i in range(1, n - 1):
        left = fractions.Fraction(x[i - 1], x[i - 1] + x[i + 1])
        right = fractions.Fraction(x[i + 1], x[i - 1] + x[i + 1])
        a[i] = right / (1 - a[i - 1] * left)
        b[i] = b[i - 1] * left / (1 - a[i - 1] * left)
    if k == n:
        return 1
    c = 1
    for i in reversed(range(k - 1, n - 1)):
        c = a[i] * c + b[i]
    return c


# generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
def main():
    import sys
    tokens = iter(sys.stdin.read().split())
    N = int(next(tokens))
    K = int(next(tokens))
    A = [None for _ in range(N)]
    for i in range(N):
        A[i] = int(next(tokens))
    assert next(tokens, None) is None
    a = solve(N, K, A)
    if a == 0:
        print(0)
    elif a == 1:
        print('1/1')
    else:
        print(a)


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