結果

問題 No.1706 Many Bus Stops (hard)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-10-08 23:04:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,662 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 76,684 KB
最終ジャッジ日時 2023-09-30 12:28:04
合計ジャッジ時間 5,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,408 KB
testcase_01 AC 69 ms
71,584 KB
testcase_02 AC 79 ms
76,372 KB
testcase_03 AC 76 ms
76,208 KB
testcase_04 AC 79 ms
76,352 KB
testcase_05 AC 79 ms
76,336 KB
testcase_06 AC 76 ms
76,252 KB
testcase_07 AC 77 ms
76,284 KB
testcase_08 AC 77 ms
76,328 KB
testcase_09 AC 78 ms
76,360 KB
testcase_10 AC 78 ms
76,372 KB
testcase_11 AC 76 ms
76,384 KB
testcase_12 AC 75 ms
76,436 KB
testcase_13 AC 79 ms
76,132 KB
testcase_14 AC 79 ms
76,332 KB
testcase_15 AC 78 ms
76,304 KB
testcase_16 AC 77 ms
76,400 KB
testcase_17 AC 80 ms
76,364 KB
testcase_18 AC 80 ms
76,380 KB
testcase_19 AC 81 ms
76,300 KB
testcase_20 AC 80 ms
76,332 KB
testcase_21 AC 79 ms
76,376 KB
testcase_22 AC 79 ms
76,428 KB
testcase_23 AC 80 ms
76,376 KB
testcase_24 AC 79 ms
76,284 KB
testcase_25 AC 82 ms
76,400 KB
testcase_26 AC 78 ms
76,684 KB
testcase_27 AC 79 ms
76,388 KB
testcase_28 AC 79 ms
76,468 KB
testcase_29 AC 78 ms
76,592 KB
testcase_30 AC 78 ms
76,348 KB
testcase_31 AC 77 ms
76,276 KB
testcase_32 AC 79 ms
76,448 KB
testcase_33 AC 78 ms
76,068 KB
testcase_34 AC 79 ms
76,092 KB
testcase_35 AC 77 ms
76,344 KB
testcase_36 AC 78 ms
76,392 KB
testcase_37 AC 77 ms
76,440 KB
testcase_38 AC 80 ms
76,512 KB
testcase_39 AC 79 ms
76,160 KB
testcase_40 AC 78 ms
76,288 KB
testcase_41 AC 77 ms
76,332 KB
testcase_42 AC 78 ms
76,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

1704&1706

行列べき乗はそれはそう。

バス停1
1 -> ?
? -> 1
? -> ?
バス停?

の5通りしか存在しないと考えてよい。

あとは、1台がいる確率をそれぞれ求めて
一台もいない確率を計算すればおk

"""
from sys import stdin
import sys

mod = 10**9+7

def inverse(x,mod):
    return pow(x,mod-2,mod)

def matrix_mul(A,B,mod):
 
    ans = [ [0] * len(B[0]) for i in range(len(A)) ]
 
    for ai in range(len(A)):
 
        for bj in range(len(B[0])):
 
            now = 0
            for same in range(len(A[0])):
                now += A[ai][same] * B[same][bj]

            if mod > 0:
                ans[ai][bj] = now % mod
            else:
                ans[ai][bj] = now
 
    return ans
 
#行列Aのx乗(当然正方行列じゃないとだめ)
def matrix_pow(A,x,mod):
 
    B = [[A[i][j] for j in range(len(A[0]))] for i in range(len(A))]
    ans = [[0] * len(A[0]) for i in range(len(A))]
    for i in range(len(A)):
        ans[i][i] = 1
 
    while x > 0:
        if x % 2 == 1:
            ans = matrix_mul(ans,B,mod)
        B = matrix_mul(B,B,mod)
 
        x//=2
    return ans

mod = 10**9+7

C,N,M = map(int,stdin.readline().split())

#バス停1
#1 -> ?
#? -> 1
#? -> ?
#バス停?

CINV = inverse(C,mod)

OA = [[1,0,0,0,0]]

A = [ [CINV , (1-CINV) % mod ,  0  ,  0  ,  0 ],
      [0    ,  0     ,  0  ,  0  ,  1 ],
      [1    ,  0     ,  0  ,  0  ,  0],
      [0    ,  0     ,  0  ,  0  , 1],
      [0    ,  0     ,  CINV , (1-2*CINV) % mod , CINV]
      ]

ansM = matrix_mul(OA,matrix_pow(A,N,mod),mod)

notone = 1 - ansM[0][0]

ans = 1 - pow(notone , M , mod)
print (ans % mod)
0