結果

問題 No.1704 Many Bus Stops (easy)
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-12 09:43:48
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,092 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 79,664 KB
最終ジャッジ日時 2023-10-15 00:16:30
合計ジャッジ時間 32,106 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
76,244 KB
testcase_01 AC 1,092 ms
78,480 KB
testcase_02 AC 404 ms
79,056 KB
testcase_03 AC 398 ms
78,604 KB
testcase_04 AC 399 ms
78,100 KB
testcase_05 AC 399 ms
78,048 KB
testcase_06 AC 403 ms
79,360 KB
testcase_07 AC 399 ms
78,028 KB
testcase_08 AC 402 ms
78,792 KB
testcase_09 AC 403 ms
78,160 KB
testcase_10 AC 405 ms
79,116 KB
testcase_11 AC 399 ms
78,044 KB
testcase_12 AC 404 ms
79,176 KB
testcase_13 AC 395 ms
78,484 KB
testcase_14 AC 402 ms
78,784 KB
testcase_15 AC 403 ms
78,664 KB
testcase_16 AC 400 ms
78,668 KB
testcase_17 AC 400 ms
78,428 KB
testcase_18 AC 402 ms
78,996 KB
testcase_19 AC 398 ms
78,076 KB
testcase_20 AC 400 ms
79,016 KB
testcase_21 AC 401 ms
79,664 KB
testcase_22 AC 941 ms
78,732 KB
testcase_23 AC 946 ms
78,508 KB
testcase_24 AC 943 ms
78,740 KB
testcase_25 AC 952 ms
78,684 KB
testcase_26 AC 951 ms
79,164 KB
testcase_27 AC 947 ms
78,636 KB
testcase_28 AC 949 ms
79,160 KB
testcase_29 AC 946 ms
78,516 KB
testcase_30 AC 965 ms
78,752 KB
testcase_31 AC 959 ms
79,116 KB
testcase_32 AC 974 ms
78,824 KB
testcase_33 AC 951 ms
78,808 KB
testcase_34 AC 970 ms
78,820 KB
testcase_35 AC 946 ms
78,988 KB
testcase_36 AC 973 ms
78,888 KB
testcase_37 AC 949 ms
78,504 KB
testcase_38 AC 978 ms
79,060 KB
testcase_39 AC 955 ms
78,240 KB
testcase_40 AC 945 ms
78,488 KB
testcase_41 AC 952 ms
78,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

# A*B
def mat_mul(A, B, mod):
    C = [[0]*len(B[0]) for i in range(len(A))]
    for i in range(len(A)):
        for k in range(len(B)):
            for j in range(len(B[0])):
                C[i][j] = (C[i][j] + A[i][k]*B[k][j])%mod
    return C

#A**n
def mat_pow(A, n, mod):
    B = [[0]*len(A) for i in range(len(A))]
    for i in range(len(A)):
        B[i][i] = 1
    while n > 0:
        if n & 1 == 1:
            B = mat_mul(A, B, mod)
        A = mat_mul(A, A, mod)
        n = n>>1
    return B

mod = 10**9+7
p = pow(3, mod-2, mod)
A = [[p,0,0,0,p,p],[0,p,0,p,0,p],[0,0,p,p,p,0],[1,0,0,0,0,0],[0,1,0,0,0,0],[0,0,1,0,0,0]]
X = [p, 0, 0, 1, 0, 0]

t = int(input())
for _ in range(t):
    n = int(input())
    M = mat_pow(A, n-1, mod)
    ans = 0
    for j in range(6):
        ans += M[0][j]*X[j]
        ans %= mod
    print(ans)
0