結果

問題 No.1704 Many Bus Stops (easy)
ユーザー rlangevinrlangevin
提出日時 2023-02-05 11:03:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,652 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 80,020 KB
最終ジャッジ日時 2023-09-17 04:22:53
合計ジャッジ時間 65,239 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
76,168 KB
testcase_01 AC 1,605 ms
79,164 KB
testcase_02 AC 1,444 ms
79,236 KB
testcase_03 AC 1,436 ms
78,768 KB
testcase_04 AC 1,448 ms
79,232 KB
testcase_05 AC 1,440 ms
78,532 KB
testcase_06 AC 1,441 ms
78,408 KB
testcase_07 AC 1,440 ms
79,216 KB
testcase_08 AC 1,443 ms
78,864 KB
testcase_09 AC 1,449 ms
79,476 KB
testcase_10 AC 1,436 ms
78,648 KB
testcase_11 AC 1,455 ms
78,712 KB
testcase_12 AC 1,440 ms
78,760 KB
testcase_13 AC 1,435 ms
78,696 KB
testcase_14 AC 1,442 ms
78,704 KB
testcase_15 AC 1,443 ms
78,560 KB
testcase_16 AC 1,443 ms
78,780 KB
testcase_17 AC 1,439 ms
79,212 KB
testcase_18 AC 1,454 ms
79,388 KB
testcase_19 AC 1,445 ms
78,716 KB
testcase_20 AC 1,447 ms
78,760 KB
testcase_21 AC 1,445 ms
79,036 KB
testcase_22 AC 1,630 ms
79,648 KB
testcase_23 AC 1,636 ms
79,404 KB
testcase_24 AC 1,623 ms
79,932 KB
testcase_25 AC 1,632 ms
79,220 KB
testcase_26 AC 1,634 ms
79,364 KB
testcase_27 AC 1,631 ms
79,372 KB
testcase_28 AC 1,633 ms
79,624 KB
testcase_29 AC 1,632 ms
79,760 KB
testcase_30 AC 1,633 ms
79,372 KB
testcase_31 AC 1,632 ms
79,580 KB
testcase_32 AC 1,629 ms
79,724 KB
testcase_33 AC 1,629 ms
79,796 KB
testcase_34 AC 1,644 ms
79,128 KB
testcase_35 AC 1,628 ms
79,716 KB
testcase_36 AC 1,642 ms
79,524 KB
testcase_37 AC 1,630 ms
79,612 KB
testcase_38 AC 1,632 ms
80,020 KB
testcase_39 AC 1,652 ms
79,200 KB
testcase_40 AC 1,641 ms
79,832 KB
testcase_41 AC 1,639 ms
79,264 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 = [[1, 0, 0, 1, 0, 1], 
     [3, 0, 0, 0, 0, 0],
     [0, 1, 1, 0,  0, 1], 
     [0, 0, 3, 0, 0, 0],
     [0, 1, 0, 1, 1, 0], 
     [0, 0, 0, 0, 3, 0],]
for _ in range(T):
    N = int(readline())
    A = Matpow(M, N, mod)
    print(A[0][0] * pow(inv, N, mod) % mod)
0