結果

問題 No.1706 Many Bus Stops (hard)
ユーザー chineristACchineristAC
提出日時 2021-09-12 01:08:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 900 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 76,444 KB
最終ジャッジ日時 2023-09-30 09:30:41
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,104 KB
testcase_01 AC 74 ms
71,256 KB
testcase_02 AC 81 ms
76,240 KB
testcase_03 AC 87 ms
76,252 KB
testcase_04 AC 82 ms
76,256 KB
testcase_05 AC 82 ms
76,304 KB
testcase_06 AC 91 ms
76,424 KB
testcase_07 AC 81 ms
76,260 KB
testcase_08 AC 82 ms
76,004 KB
testcase_09 AC 81 ms
76,380 KB
testcase_10 AC 82 ms
76,296 KB
testcase_11 AC 83 ms
76,412 KB
testcase_12 AC 81 ms
76,168 KB
testcase_13 AC 81 ms
76,184 KB
testcase_14 AC 82 ms
76,204 KB
testcase_15 AC 83 ms
75,976 KB
testcase_16 AC 82 ms
76,248 KB
testcase_17 AC 83 ms
76,284 KB
testcase_18 AC 82 ms
76,256 KB
testcase_19 AC 81 ms
76,284 KB
testcase_20 AC 82 ms
76,184 KB
testcase_21 AC 82 ms
76,272 KB
testcase_22 AC 82 ms
76,276 KB
testcase_23 AC 83 ms
76,232 KB
testcase_24 AC 83 ms
76,000 KB
testcase_25 AC 82 ms
76,248 KB
testcase_26 AC 81 ms
76,372 KB
testcase_27 AC 82 ms
76,208 KB
testcase_28 AC 82 ms
76,284 KB
testcase_29 AC 85 ms
76,328 KB
testcase_30 AC 83 ms
76,180 KB
testcase_31 AC 83 ms
76,268 KB
testcase_32 AC 84 ms
76,084 KB
testcase_33 AC 84 ms
76,176 KB
testcase_34 AC 84 ms
76,212 KB
testcase_35 AC 83 ms
76,184 KB
testcase_36 AC 84 ms
76,004 KB
testcase_37 AC 83 ms
76,004 KB
testcase_38 AC 82 ms
76,208 KB
testcase_39 AC 82 ms
76,232 KB
testcase_40 AC 82 ms
76,444 KB
testcase_41 AC 80 ms
76,008 KB
testcase_42 AC 81 ms
76,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7

def mat_mul(X,Y):
    n,m = len(X),len(Y[0])
    res = [[0 for j in range(m)] for i in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(len(Y)):
                res[i][j] += X[i][k] * Y[k][j]
                res[i][j] %= mod
    return res

i3 = pow(3,mod-2,mod)



def solve(C,N,M):
    iC = pow(C,mod-2,mod)
    A = [
    [iC,0,0,iC],
    [0,iC,(C-1)*iC,(C-2)*iC],
    [1,0,0,0],
    [0,1,0,0]
    ]

    assert 1 <= N <= 10**9
    base = [[1],[0],[0],[0]]
    mat = [[int(i==j) for j in range(4)] for i in range(4)]
    tmp = [[A[i][j] for j in range(4)] for i in range(4)]
    while N:
        if N&1:
            mat = mat_mul(tmp,mat)
        tmp = mat_mul(tmp,tmp)
        N >>= 1
    base = mat_mul(mat,base)
    p = base[0][0]
    res = 1 - pow(1-p,M,mod)
    return res % mod

C,N,M = map(int,input().split())
print(solve(C,N,M))
    
0