結果

問題 No.1706 Many Bus Stops (hard)
ユーザー mkawa2mkawa2
提出日時 2021-10-08 23:50:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,530 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 76,608 KB
最終ジャッジ日時 2023-09-30 14:17:11
合計ジャッジ時間 5,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,432 KB
testcase_01 AC 79 ms
76,056 KB
testcase_02 AC 79 ms
76,440 KB
testcase_03 AC 81 ms
76,388 KB
testcase_04 AC 80 ms
76,608 KB
testcase_05 AC 80 ms
76,348 KB
testcase_06 AC 80 ms
76,304 KB
testcase_07 AC 80 ms
76,396 KB
testcase_08 AC 81 ms
76,268 KB
testcase_09 AC 81 ms
76,344 KB
testcase_10 AC 81 ms
76,408 KB
testcase_11 AC 80 ms
76,516 KB
testcase_12 AC 81 ms
76,416 KB
testcase_13 AC 80 ms
76,268 KB
testcase_14 AC 84 ms
76,260 KB
testcase_15 AC 79 ms
76,384 KB
testcase_16 AC 80 ms
76,268 KB
testcase_17 AC 80 ms
76,108 KB
testcase_18 AC 80 ms
76,388 KB
testcase_19 AC 79 ms
76,372 KB
testcase_20 AC 79 ms
76,532 KB
testcase_21 AC 81 ms
76,360 KB
testcase_22 AC 80 ms
76,300 KB
testcase_23 AC 79 ms
76,424 KB
testcase_24 AC 78 ms
76,264 KB
testcase_25 AC 80 ms
76,288 KB
testcase_26 AC 80 ms
76,064 KB
testcase_27 AC 81 ms
76,364 KB
testcase_28 AC 80 ms
76,320 KB
testcase_29 AC 79 ms
76,320 KB
testcase_30 AC 78 ms
76,316 KB
testcase_31 AC 79 ms
76,288 KB
testcase_32 AC 79 ms
76,604 KB
testcase_33 AC 80 ms
76,364 KB
testcase_34 AC 79 ms
76,452 KB
testcase_35 AC 81 ms
76,328 KB
testcase_36 AC 80 ms
76,364 KB
testcase_37 AC 79 ms
76,424 KB
testcase_38 AC 79 ms
76,296 KB
testcase_39 AC 80 ms
76,300 KB
testcase_40 AC 81 ms
76,400 KB
testcase_41 AC 79 ms
76,312 KB
testcase_42 AC 79 ms
76,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**19
# md = 998244353
md = 10**9+7

def dot(aa, bb):
    h = len(aa)
    w = len(bb[0])
    res = [[0]*w for _ in range(h)]
    for i, row in enumerate(aa):
        for j, col in enumerate(zip(*bb)):
            v = 0
            # for a, b in zip(row, col): v += a*b
            # res[i][j] = v%md
            for a, b in zip(row, col): v += a*b%md
            res[i][j] = v%md
    return res

def matpow(e):
    n = 4
    res = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    i = 0
    while e:
        if e & 1: res = dot(res, mm[i])
        e >>= 1
        i += 1
    return res

c, n, m = LI()

inv = pow(c, md-2, md)

mat = [[0, 0, 0, inv]
    , [0, 0, inv*(c-1)%md, inv*(c-2)%md]
    , [1, 0, inv, 0]
    , [0, 1, 0, inv]]

lim = 10**9+5

i = 1
mm = []
while i < lim:
    mm.append(mat)
    mat = dot(mat, mat)
    i <<= 1

p = matpow(n)[2][2]%md
ans = (1-pow(1-p, m, md))%md
print(ans)
0