結果

問題 No.1706 Many Bus Stops (hard)
ユーザー tassei903tassei903
提出日時 2021-10-08 23:44:16
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 76,544 KB
最終ジャッジ日時 2023-09-30 14:06:45
合計ジャッジ時間 5,946 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,432 KB
testcase_01 AC 74 ms
71,516 KB
testcase_02 AC 88 ms
76,136 KB
testcase_03 AC 86 ms
76,468 KB
testcase_04 AC 85 ms
76,440 KB
testcase_05 AC 86 ms
76,392 KB
testcase_06 AC 85 ms
76,408 KB
testcase_07 AC 86 ms
76,424 KB
testcase_08 AC 86 ms
76,428 KB
testcase_09 AC 86 ms
76,512 KB
testcase_10 AC 84 ms
76,436 KB
testcase_11 AC 84 ms
76,448 KB
testcase_12 AC 87 ms
76,500 KB
testcase_13 AC 88 ms
76,444 KB
testcase_14 AC 88 ms
76,496 KB
testcase_15 AC 87 ms
76,416 KB
testcase_16 AC 85 ms
76,448 KB
testcase_17 AC 85 ms
76,436 KB
testcase_18 AC 87 ms
76,376 KB
testcase_19 AC 86 ms
76,312 KB
testcase_20 AC 86 ms
76,324 KB
testcase_21 AC 84 ms
76,320 KB
testcase_22 AC 87 ms
76,484 KB
testcase_23 AC 86 ms
76,340 KB
testcase_24 AC 88 ms
76,372 KB
testcase_25 AC 87 ms
76,332 KB
testcase_26 AC 87 ms
76,280 KB
testcase_27 AC 88 ms
76,488 KB
testcase_28 AC 86 ms
76,344 KB
testcase_29 AC 87 ms
76,448 KB
testcase_30 AC 86 ms
76,428 KB
testcase_31 AC 89 ms
76,448 KB
testcase_32 AC 90 ms
76,424 KB
testcase_33 AC 89 ms
76,464 KB
testcase_34 AC 89 ms
76,544 KB
testcase_35 AC 85 ms
76,308 KB
testcase_36 AC 87 ms
76,356 KB
testcase_37 AC 87 ms
76,492 KB
testcase_38 AC 86 ms
76,316 KB
testcase_39 AC 85 ms
76,408 KB
testcase_40 AC 87 ms
76,332 KB
testcase_41 AC 88 ms
76,480 KB
testcase_42 AC 85 ms
76,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################



#a*bの計算
def mat_mul(a,b):
    n,m,l=len(a),len(b[0]),len(b)
    c=[[0]*m for _ in range(n)]
    for i in range(n):
        for k in range(l):
            for  j in range(m):
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod
    return c
 
#a^nの計算
def mat_pow(a,n):
    m=len(a)
    b=[[0]*m for _ in range(m)]
    for i in range(m):
        b[i][i]=1
    while n>0:
        if n&1:
            b=mat_mul(b,a)
        a=mat_mul(a,a)
        n>>=1
    return b



c,n,m = na()
p = mod = 10**9+7
z = pow(c,p-2,p)
s = list(zip([z,0,1,0]))
b = [[z,0,0,z],[0,z,z*(c-1),z*(c-2)],[1,0,0,0],[0,1,0,0]]


if n==1:
    print((1-pow(1-z, m, mod))%mod)
else:
    p = mat_mul(mat_pow(b,n-1),s)
    #print(mat_mul(mat_pow(b,n-1),s))
    print((1-pow(1-mat_mul(mat_pow(b,n-1),s)[0][0],m,mod))%mod)
0