結果

問題 No.1706 Many Bus Stops (hard)
ユーザー 👑 tamatotamato
提出日時 2021-10-08 22:48:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 87,756 KB
実行使用メモリ 76,944 KB
最終ジャッジ日時 2023-09-30 11:55:27
合計ジャッジ時間 5,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,592 KB
testcase_01 AC 70 ms
71,628 KB
testcase_02 AC 76 ms
76,584 KB
testcase_03 AC 77 ms
76,664 KB
testcase_04 AC 83 ms
76,744 KB
testcase_05 AC 77 ms
76,764 KB
testcase_06 AC 77 ms
76,752 KB
testcase_07 AC 77 ms
76,600 KB
testcase_08 AC 77 ms
76,708 KB
testcase_09 AC 76 ms
76,728 KB
testcase_10 AC 81 ms
76,560 KB
testcase_11 AC 78 ms
76,716 KB
testcase_12 AC 78 ms
76,712 KB
testcase_13 AC 78 ms
76,792 KB
testcase_14 AC 78 ms
76,664 KB
testcase_15 AC 77 ms
76,600 KB
testcase_16 AC 77 ms
76,456 KB
testcase_17 AC 78 ms
76,756 KB
testcase_18 AC 77 ms
76,492 KB
testcase_19 AC 77 ms
76,716 KB
testcase_20 AC 78 ms
76,716 KB
testcase_21 AC 80 ms
76,720 KB
testcase_22 AC 79 ms
76,612 KB
testcase_23 AC 78 ms
76,776 KB
testcase_24 AC 77 ms
76,608 KB
testcase_25 AC 79 ms
76,736 KB
testcase_26 AC 77 ms
76,664 KB
testcase_27 AC 76 ms
76,748 KB
testcase_28 AC 78 ms
76,616 KB
testcase_29 AC 80 ms
76,664 KB
testcase_30 AC 77 ms
76,912 KB
testcase_31 AC 79 ms
76,612 KB
testcase_32 AC 78 ms
76,488 KB
testcase_33 AC 78 ms
76,544 KB
testcase_34 AC 79 ms
76,604 KB
testcase_35 AC 78 ms
76,764 KB
testcase_36 AC 76 ms
76,452 KB
testcase_37 AC 78 ms
76,500 KB
testcase_38 AC 76 ms
76,944 KB
testcase_39 AC 78 ms
76,752 KB
testcase_40 AC 77 ms
76,596 KB
testcase_41 AC 79 ms
76,616 KB
testcase_42 AC 78 ms
76,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def matmul(A, B):
        C = [[0] * len(B[0]) for _ in range(len(A))]
        for i in range(len(A)):
            for k in range(len(B)):
                for j in range(len(B[0])):
                    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod
        return C

    def matpow(A, p):
        n = len(A)
        B = [[0] * n for _ in range(n)]
        for i in range(n):
            B[i][i] = 1
        while p > 0:
            if p & 1:
                B = matmul(B, A)
            A = matmul(A, A)
            p >>= 1
        return B

    C, N, M = map(int, input().split())
    invC = pow(C, mod - 2, mod)
    mat = [[0] * 4 for _ in range(4)]
    mat[0][0] = invC
    mat[0][3] = (1 - invC)%mod
    mat[1][1] = invC
    mat[1][2] = invC
    mat[1][3] = (1 - 2*invC)%mod
    mat[2][0] = 1
    mat[3][1] = 1
    vec = [[0] for _ in range(4)]
    vec[0][0] = 1

    p = (1 - matmul(matpow(mat, N), vec)[0][0])%mod
    print((1 - pow(p, M, mod))%mod)


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