結果

問題 No.1704 Many Bus Stops (easy)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-10-08 23:08:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 449 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 86,420 KB
実行使用メモリ 80,124 KB
最終ジャッジ日時 2023-09-30 12:38:53
合計ジャッジ時間 16,487 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,892 KB
testcase_01 AC 436 ms
78,508 KB
testcase_02 AC 248 ms
78,300 KB
testcase_03 AC 248 ms
78,416 KB
testcase_04 AC 247 ms
78,208 KB
testcase_05 AC 248 ms
78,496 KB
testcase_06 AC 249 ms
79,004 KB
testcase_07 AC 249 ms
78,324 KB
testcase_08 AC 244 ms
78,580 KB
testcase_09 AC 254 ms
78,192 KB
testcase_10 AC 245 ms
78,704 KB
testcase_11 AC 252 ms
78,472 KB
testcase_12 AC 246 ms
77,972 KB
testcase_13 AC 245 ms
78,108 KB
testcase_14 AC 255 ms
78,756 KB
testcase_15 AC 247 ms
78,608 KB
testcase_16 AC 251 ms
78,364 KB
testcase_17 AC 253 ms
78,636 KB
testcase_18 AC 245 ms
78,124 KB
testcase_19 AC 251 ms
78,456 KB
testcase_20 AC 246 ms
78,924 KB
testcase_21 AC 249 ms
78,372 KB
testcase_22 AC 441 ms
79,708 KB
testcase_23 AC 442 ms
79,388 KB
testcase_24 AC 442 ms
79,104 KB
testcase_25 AC 438 ms
79,444 KB
testcase_26 AC 449 ms
79,940 KB
testcase_27 AC 449 ms
79,552 KB
testcase_28 AC 440 ms
79,316 KB
testcase_29 AC 442 ms
79,520 KB
testcase_30 AC 442 ms
79,800 KB
testcase_31 AC 439 ms
79,356 KB
testcase_32 AC 443 ms
80,072 KB
testcase_33 AC 444 ms
79,792 KB
testcase_34 AC 444 ms
79,336 KB
testcase_35 AC 449 ms
79,528 KB
testcase_36 AC 441 ms
79,656 KB
testcase_37 AC 445 ms
79,284 KB
testcase_38 AC 446 ms
79,892 KB
testcase_39 AC 441 ms
80,124 KB
testcase_40 AC 442 ms
79,360 KB
testcase_41 AC 443 ms
79,772 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

TT = int(stdin.readline())

ANS = []
for loop in range(TT):

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

    #バス停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)

    ANS.append(str(ansM[0][0] % mod))

    #notone = 1 - ansM[0][0]

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

print ("\n".join(ANS))
0