結果

問題 No.1704 Many Bus Stops (easy)
ユーザー rlangevinrlangevin
提出日時 2023-02-05 11:04:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,037 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 79,448 KB
最終ジャッジ日時 2023-09-17 04:24:22
合計ジャッジ時間 37,842 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,704 KB
testcase_01 AC 860 ms
79,448 KB
testcase_02 AC 733 ms
78,500 KB
testcase_03 AC 741 ms
78,416 KB
testcase_04 AC 731 ms
78,656 KB
testcase_05 AC 721 ms
78,228 KB
testcase_06 AC 736 ms
78,612 KB
testcase_07 AC 741 ms
78,672 KB
testcase_08 AC 721 ms
78,672 KB
testcase_09 AC 713 ms
78,524 KB
testcase_10 AC 735 ms
78,164 KB
testcase_11 AC 722 ms
78,500 KB
testcase_12 AC 722 ms
78,688 KB
testcase_13 AC 725 ms
78,756 KB
testcase_14 AC 716 ms
78,260 KB
testcase_15 AC 715 ms
78,392 KB
testcase_16 AC 724 ms
78,368 KB
testcase_17 AC 728 ms
78,708 KB
testcase_18 AC 747 ms
78,456 KB
testcase_19 AC 717 ms
78,712 KB
testcase_20 AC 723 ms
78,428 KB
testcase_21 AC 720 ms
78,580 KB
testcase_22 AC 886 ms
78,760 KB
testcase_23 AC 877 ms
78,504 KB
testcase_24 AC 876 ms
79,204 KB
testcase_25 AC 887 ms
79,104 KB
testcase_26 AC 897 ms
78,784 KB
testcase_27 AC 885 ms
78,908 KB
testcase_28 AC 883 ms
78,668 KB
testcase_29 AC 884 ms
79,092 KB
testcase_30 AC 882 ms
79,152 KB
testcase_31 AC 889 ms
78,404 KB
testcase_32 AC 904 ms
79,308 KB
testcase_33 AC 889 ms
78,404 KB
testcase_34 AC 904 ms
79,004 KB
testcase_35 AC 884 ms
78,572 KB
testcase_36 AC 1,031 ms
78,412 KB
testcase_37 AC 1,037 ms
79,072 KB
testcase_38 AC 1,034 ms
78,572 KB
testcase_39 AC 901 ms
79,188 KB
testcase_40 AC 908 ms
78,748 KB
testcase_41 AC 901 ms
79,164 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(32):
        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