結果

問題 No.1704 Many Bus Stops (easy)
ユーザー rlangevinrlangevin
提出日時 2023-02-05 10:59:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,527 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 918 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 79,952 KB
最終ジャッジ日時 2023-09-17 04:20:15
合計ジャッジ時間 61,286 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,080 KB
testcase_01 AC 1,463 ms
78,888 KB
testcase_02 AC 1,329 ms
78,732 KB
testcase_03 AC 1,315 ms
78,708 KB
testcase_04 AC 1,333 ms
79,176 KB
testcase_05 AC 1,321 ms
78,460 KB
testcase_06 AC 1,315 ms
78,508 KB
testcase_07 AC 1,301 ms
79,064 KB
testcase_08 AC 1,332 ms
78,576 KB
testcase_09 AC 1,323 ms
79,304 KB
testcase_10 AC 1,321 ms
78,504 KB
testcase_11 AC 1,306 ms
78,660 KB
testcase_12 AC 1,319 ms
78,572 KB
testcase_13 AC 1,330 ms
78,484 KB
testcase_14 AC 1,325 ms
78,688 KB
testcase_15 AC 1,322 ms
78,496 KB
testcase_16 AC 1,319 ms
78,536 KB
testcase_17 AC 1,328 ms
79,328 KB
testcase_18 AC 1,343 ms
79,336 KB
testcase_19 AC 1,327 ms
78,512 KB
testcase_20 AC 1,345 ms
78,520 KB
testcase_21 AC 1,333 ms
78,684 KB
testcase_22 AC 1,517 ms
79,540 KB
testcase_23 AC 1,490 ms
79,204 KB
testcase_24 AC 1,489 ms
79,800 KB
testcase_25 AC 1,473 ms
79,424 KB
testcase_26 AC 1,486 ms
79,576 KB
testcase_27 AC 1,482 ms
79,072 KB
testcase_28 AC 1,499 ms
79,628 KB
testcase_29 AC 1,481 ms
79,684 KB
testcase_30 AC 1,489 ms
79,224 KB
testcase_31 AC 1,487 ms
79,516 KB
testcase_32 AC 1,482 ms
79,616 KB
testcase_33 AC 1,484 ms
79,620 KB
testcase_34 AC 1,513 ms
78,740 KB
testcase_35 AC 1,497 ms
79,800 KB
testcase_36 AC 1,506 ms
79,284 KB
testcase_37 AC 1,482 ms
79,620 KB
testcase_38 AC 1,517 ms
79,732 KB
testcase_39 AC 1,496 ms
79,152 KB
testcase_40 AC 1,504 ms
79,952 KB
testcase_41 AC 1,527 ms
79,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def Matprod(A, B, mod):
    N = len(A)
    temp = [[0] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                temp[i][j] += A[i][k] * B[k][j]
                temp[i][j] %= mod
    return temp

def Matpow(A, M, mod):
    N = len(A)
    Mat = [[0] * N for i in range(N)]
    for i in range(N):
        Mat[i][i] = 1
         
    for i in range(64):
        if (M >> i) & 1:
            Mat = Matprod(Mat, A, mod)
        A = Matprod(A, A, mod)
    return Mat  


T = int(readline())
mod = 10 ** 9 + 7
inv = pow(3, mod - 2, mod)
M = [[inv, 0, 0, inv, 0, inv], 
     [1, 0, 0, 0, 0, 0],
     [0, inv, inv, 0,  0, inv], 
     [0, 0, 1, 0, 0, 0],
     [0, inv, 0, inv, inv, 0], 
     [0, 0, 0, 0, 1, 0],]
for _ in range(T):
    N = int(readline())
    A = Matpow(M, N, mod)
    print(A[0][0])
0