結果

問題 No.1704 Many Bus Stops (easy)
ユーザー 👑 tamatotamato
提出日時 2021-10-08 22:27:59
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 590 ms / 2,000 ms
コード長 1,166 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 87,720 KB
実行使用メモリ 79,460 KB
最終ジャッジ日時 2023-09-30 11:02:18
合計ジャッジ時間 20,315 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
76,608 KB
testcase_01 AC 585 ms
78,804 KB
testcase_02 AC 291 ms
79,460 KB
testcase_03 AC 288 ms
78,588 KB
testcase_04 AC 290 ms
78,908 KB
testcase_05 AC 292 ms
78,800 KB
testcase_06 AC 294 ms
79,124 KB
testcase_07 AC 291 ms
78,356 KB
testcase_08 AC 291 ms
78,764 KB
testcase_09 AC 290 ms
79,000 KB
testcase_10 AC 295 ms
79,164 KB
testcase_11 AC 291 ms
78,796 KB
testcase_12 AC 291 ms
78,648 KB
testcase_13 AC 294 ms
79,192 KB
testcase_14 AC 366 ms
79,236 KB
testcase_15 AC 300 ms
78,848 KB
testcase_16 AC 295 ms
78,592 KB
testcase_17 AC 293 ms
78,500 KB
testcase_18 AC 293 ms
78,532 KB
testcase_19 AC 292 ms
78,972 KB
testcase_20 AC 290 ms
78,760 KB
testcase_21 AC 291 ms
78,848 KB
testcase_22 AC 583 ms
78,576 KB
testcase_23 AC 577 ms
78,836 KB
testcase_24 AC 586 ms
78,852 KB
testcase_25 AC 584 ms
79,196 KB
testcase_26 AC 587 ms
79,376 KB
testcase_27 AC 581 ms
78,672 KB
testcase_28 AC 585 ms
78,908 KB
testcase_29 AC 584 ms
78,852 KB
testcase_30 AC 586 ms
78,640 KB
testcase_31 AC 587 ms
78,792 KB
testcase_32 AC 586 ms
78,632 KB
testcase_33 AC 590 ms
79,120 KB
testcase_34 AC 580 ms
78,616 KB
testcase_35 AC 583 ms
78,888 KB
testcase_36 AC 586 ms
78,660 KB
testcase_37 AC 587 ms
78,816 KB
testcase_38 AC 586 ms
78,976 KB
testcase_39 AC 588 ms
78,980 KB
testcase_40 AC 580 ms
79,096 KB
testcase_41 AC 589 ms
78,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def matmul(A, B):
        C = [[0] * len(B[0]) for _ 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

    def matpow(A, p):
        n = len(A)
        B = [[0] * n for _ in range(n)]
        for i in range(n):
            B[i][i] = 1
        while p > 0:
            if p & 1:
                B = matmul(B, A)
            A = matmul(A, A)
            p >>= 1
        return B

    inv3 = pow(3, mod-2, mod)
    mat = [[0] * 6 for _ in range(6)]
    mat[0][0] = inv3
    mat[0][4] = inv3
    mat[0][5] = inv3
    mat[1][1] = inv3
    mat[1][3] = inv3
    mat[1][5] = inv3
    mat[2][2] = inv3
    mat[2][3] = inv3
    mat[2][4] = inv3
    mat[3][0] = 1
    mat[4][1] = 1
    mat[5][2] = 1
    vec = [[0] for _ in range(6)]
    vec[0][0] = 1

    for _ in range(int(input())):
        N = int(input())
        ans = matmul(matpow(mat, N), vec)
        print(ans[0][0])


if __name__ == '__main__':
    main()
0