結果

問題 No.1706 Many Bus Stops (hard)
ユーザー puznekopuzneko
提出日時 2021-10-30 00:32:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,014 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 61,184 KB
最終ジャッジ日時 2024-04-16 16:04:55
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 39 ms
52,352 KB
testcase_02 AC 48 ms
60,544 KB
testcase_03 AC 48 ms
60,672 KB
testcase_04 AC 47 ms
60,800 KB
testcase_05 AC 48 ms
60,928 KB
testcase_06 AC 47 ms
60,800 KB
testcase_07 AC 50 ms
60,672 KB
testcase_08 AC 51 ms
61,056 KB
testcase_09 AC 47 ms
60,800 KB
testcase_10 AC 47 ms
61,184 KB
testcase_11 AC 48 ms
60,800 KB
testcase_12 AC 47 ms
60,800 KB
testcase_13 AC 46 ms
60,892 KB
testcase_14 AC 48 ms
60,544 KB
testcase_15 AC 46 ms
60,800 KB
testcase_16 AC 47 ms
60,800 KB
testcase_17 AC 47 ms
60,928 KB
testcase_18 AC 47 ms
60,928 KB
testcase_19 AC 47 ms
60,416 KB
testcase_20 AC 47 ms
61,056 KB
testcase_21 AC 47 ms
60,800 KB
testcase_22 AC 47 ms
60,288 KB
testcase_23 AC 49 ms
60,416 KB
testcase_24 AC 48 ms
60,800 KB
testcase_25 AC 48 ms
60,928 KB
testcase_26 AC 47 ms
60,928 KB
testcase_27 AC 47 ms
60,800 KB
testcase_28 AC 46 ms
60,288 KB
testcase_29 AC 46 ms
60,672 KB
testcase_30 AC 48 ms
61,056 KB
testcase_31 AC 47 ms
61,056 KB
testcase_32 AC 48 ms
60,996 KB
testcase_33 AC 47 ms
60,928 KB
testcase_34 AC 46 ms
60,800 KB
testcase_35 AC 47 ms
60,544 KB
testcase_36 AC 48 ms
60,800 KB
testcase_37 AC 47 ms
60,800 KB
testcase_38 AC 47 ms
60,800 KB
testcase_39 AC 47 ms
60,672 KB
testcase_40 AC 47 ms
60,416 KB
testcase_41 AC 48 ms
60,544 KB
testcase_42 AC 47 ms
61,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def powmod(n,pow,mod):
    val = 1
    while pow > 0:
        if pow & 1:
            val = (val * n) % mod
        pow = pow >> 1
        n = (n * n) % mod
    return val

def matdot(a,b,mod):
    matsize = len(a)
    val = [[0 for i in range(matsize)] for j in range(matsize)]
    for i in range(matsize):
        for j in range(matsize):
            for k in range(matsize):
                val[i][j] = (val[i][j] + a[i][k] * b[k][j]) % mod
    return val

def powmodmat(n,pow,mod):
    matsize = len(n)
    val = [[0 for i in range(matsize)] for j in range(matsize)]
    for i in range(matsize):
        val[i][i] = 1
    while pow > 0:
        if pow & 1:
            val = matdot(val, n, mod)
        pow = pow >> 1
        n = matdot(n, n, mod)
    return val

c, n, m = map(int, input().split())
p = 10**9+7
inv = powmod(c,p-2,p)
mat = [[inv,0,0,inv*(c-1)%p],[0,inv,inv,inv*(c-2)%p],[1,0,0,0],[0,1,0,0]]
kari = powmodmat(mat,n,p)
a = kari[0][0]
ans = (1 - powmod((1-a)%p,m,p)) % p
print("{}".format(ans))

0