結果

問題 No.1706 Many Bus Stops (hard)
ユーザー titiatitia
提出日時 2021-10-09 05:45:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 979 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 8,524 KB
最終ジャッジ日時 2023-09-30 22:34:28
合計ジャッジ時間 3,536 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,456 KB
testcase_01 AC 19 ms
8,448 KB
testcase_02 AC 19 ms
8,276 KB
testcase_03 AC 19 ms
8,344 KB
testcase_04 AC 18 ms
8,356 KB
testcase_05 AC 18 ms
8,444 KB
testcase_06 AC 19 ms
8,304 KB
testcase_07 AC 18 ms
8,384 KB
testcase_08 AC 18 ms
8,348 KB
testcase_09 AC 19 ms
8,388 KB
testcase_10 AC 18 ms
8,336 KB
testcase_11 AC 18 ms
8,460 KB
testcase_12 AC 18 ms
8,508 KB
testcase_13 AC 18 ms
8,212 KB
testcase_14 AC 18 ms
8,040 KB
testcase_15 AC 18 ms
8,464 KB
testcase_16 AC 18 ms
8,388 KB
testcase_17 AC 18 ms
8,460 KB
testcase_18 AC 19 ms
8,376 KB
testcase_19 AC 18 ms
8,444 KB
testcase_20 AC 18 ms
8,276 KB
testcase_21 AC 18 ms
8,360 KB
testcase_22 AC 18 ms
8,484 KB
testcase_23 AC 18 ms
8,336 KB
testcase_24 AC 18 ms
8,380 KB
testcase_25 AC 18 ms
8,352 KB
testcase_26 AC 18 ms
8,176 KB
testcase_27 AC 18 ms
8,456 KB
testcase_28 AC 19 ms
8,424 KB
testcase_29 AC 18 ms
8,448 KB
testcase_30 AC 18 ms
8,404 KB
testcase_31 AC 18 ms
8,308 KB
testcase_32 AC 18 ms
8,136 KB
testcase_33 AC 19 ms
8,320 KB
testcase_34 AC 19 ms
8,452 KB
testcase_35 AC 18 ms
8,344 KB
testcase_36 AC 18 ms
8,388 KB
testcase_37 AC 18 ms
8,456 KB
testcase_38 AC 18 ms
8,344 KB
testcase_39 AC 18 ms
8,316 KB
testcase_40 AC 18 ms
8,524 KB
testcase_41 AC 18 ms
8,388 KB
testcase_42 AC 19 ms
8,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7

# 行列の計算(numpyを使えないとき,modを使用)
def prod(A,B,k,l,m):# A:k*l,B:l*m
    C=[[None for i in range(m)] for j in range(k)]

    for i in range(k):
        for j in range(m):
            ANS=0
            for pl in range(l):
                ANS=(ANS+A[i][pl]*B[pl][j])%mod

            C[i][j]=ANS

    return C

def plus(A,B,k,l):# a,B:k*l
    C=[[None for i in range(l)] for j in range(k)]

    for i in range(k):
        for j in range(l):
            C[i][j]=(A[i][j]+B[i][j])%mod

    return C

C,n,M=map(int,input().split())

INV=pow(C,mod-2,mod)

A=[[0]*4 for i in range(4)]

A[0][0]=INV
A[0][3]=1-INV
A[1][1]=INV
A[1][2]=INV
A[1][3]=1-INV*2
A[2][0]=1
A[3][1]=1

POWA=[A]
for i in range(60):
    POWA.append(prod(POWA[-1],POWA[-1],4,4,4)) # ベキを求めて


X=[[1,0,0,0]]

while n:
    X=prod(X,POWA[n.bit_length()-1],1,4,4) # n乗の場合
    n-=1<<(n.bit_length()-1)

#print(X[0][0])

t=X[0][0]

print((1-pow((1-t),M,mod))%mod)
0