結果

問題 No.1706 Many Bus Stops (hard)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:26:32
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 75,960 KB
最終ジャッジ日時 2023-09-30 13:26:55
合計ジャッジ時間 5,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,284 KB
testcase_01 AC 75 ms
71,572 KB
testcase_02 AC 84 ms
75,548 KB
testcase_03 AC 85 ms
75,500 KB
testcase_04 AC 85 ms
75,736 KB
testcase_05 AC 86 ms
75,652 KB
testcase_06 AC 82 ms
75,628 KB
testcase_07 AC 82 ms
75,652 KB
testcase_08 AC 84 ms
75,628 KB
testcase_09 AC 83 ms
75,620 KB
testcase_10 AC 86 ms
75,772 KB
testcase_11 AC 86 ms
75,616 KB
testcase_12 AC 85 ms
75,540 KB
testcase_13 AC 83 ms
75,612 KB
testcase_14 AC 85 ms
75,608 KB
testcase_15 AC 85 ms
75,496 KB
testcase_16 AC 84 ms
75,648 KB
testcase_17 AC 85 ms
75,732 KB
testcase_18 AC 86 ms
75,948 KB
testcase_19 AC 83 ms
75,676 KB
testcase_20 AC 82 ms
75,960 KB
testcase_21 AC 81 ms
75,776 KB
testcase_22 AC 84 ms
75,676 KB
testcase_23 AC 83 ms
75,612 KB
testcase_24 AC 84 ms
75,744 KB
testcase_25 AC 83 ms
75,656 KB
testcase_26 AC 82 ms
75,544 KB
testcase_27 AC 82 ms
75,740 KB
testcase_28 AC 82 ms
75,544 KB
testcase_29 AC 84 ms
75,736 KB
testcase_30 AC 85 ms
75,684 KB
testcase_31 AC 84 ms
75,504 KB
testcase_32 AC 83 ms
75,772 KB
testcase_33 AC 84 ms
75,596 KB
testcase_34 AC 82 ms
75,732 KB
testcase_35 AC 82 ms
75,748 KB
testcase_36 AC 82 ms
75,656 KB
testcase_37 AC 80 ms
75,612 KB
testcase_38 AC 83 ms
75,744 KB
testcase_39 AC 83 ms
75,616 KB
testcase_40 AC 83 ms
75,760 KB
testcase_41 AC 84 ms
75,712 KB
testcase_42 AC 84 ms
75,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

C, N, M = map(int, input().split())
MOD = 10 ** 9 + 7
iC = pow(C, MOD - 2, MOD)

"""pypy用行列累乗ライブラリは https://github.com/fujihiraryo/alogorithm-python/blob/master/integer/matrix.py から拝借しています。"""


def product(a, b, p=MOD):
    n = len(a)
    c = [[0] * n for i in range(n)]
    for i in range(n):
        for j in range(n):
            c[i][j] = sum([a[i][k] * b[k][j] for k in range(n)]) % p
    return c


def matpow(a, k, p=MOD):
    if k == 1:
        return a
    if k % 2 == 0:
        b = matpow(a, k // 2)
        return product(b, b, p=p)
    return product(a, matpow(a, k - 1), p=p)


A = [[iC, 0, 0, 1 - iC],
     [0, iC, iC, 1 - 2 * iC],
     [1, 0, 0, 0],
     [0, 1, 0, 0]]
tmp = matpow(A, N)[0][0]
ans = (1 - pow(1 - tmp, M, MOD)) % MOD
print(ans)
0