結果

問題 No.1704 Many Bus Stops (easy)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:06:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,749 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 89,592 KB
最終ジャッジ日時 2024-07-23 06:37:17
合計ジャッジ時間 46,319 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
68,296 KB
testcase_01 AC 1,566 ms
87,912 KB
testcase_02 AC 531 ms
78,732 KB
testcase_03 AC 533 ms
78,400 KB
testcase_04 AC 546 ms
78,780 KB
testcase_05 AC 505 ms
78,916 KB
testcase_06 AC 511 ms
78,720 KB
testcase_07 AC 536 ms
78,760 KB
testcase_08 AC 549 ms
78,992 KB
testcase_09 AC 512 ms
78,324 KB
testcase_10 AC 547 ms
79,652 KB
testcase_11 AC 569 ms
78,620 KB
testcase_12 AC 561 ms
78,408 KB
testcase_13 AC 579 ms
78,404 KB
testcase_14 AC 545 ms
78,560 KB
testcase_15 AC 566 ms
78,656 KB
testcase_16 AC 536 ms
78,100 KB
testcase_17 AC 576 ms
78,668 KB
testcase_18 AC 678 ms
78,428 KB
testcase_19 AC 564 ms
79,124 KB
testcase_20 AC 570 ms
78,708 KB
testcase_21 AC 540 ms
78,228 KB
testcase_22 AC 1,617 ms
89,208 KB
testcase_23 AC 1,560 ms
89,048 KB
testcase_24 AC 1,592 ms
89,460 KB
testcase_25 AC 1,437 ms
88,700 KB
testcase_26 AC 1,488 ms
88,692 KB
testcase_27 AC 1,643 ms
88,756 KB
testcase_28 AC 1,746 ms
89,300 KB
testcase_29 AC 1,730 ms
88,668 KB
testcase_30 AC 1,749 ms
89,532 KB
testcase_31 AC 1,669 ms
89,100 KB
testcase_32 AC 1,638 ms
88,644 KB
testcase_33 AC 1,664 ms
88,896 KB
testcase_34 AC 1,530 ms
89,592 KB
testcase_35 AC 1,569 ms
89,032 KB
testcase_36 AC 1,518 ms
88,320 KB
testcase_37 AC 1,559 ms
88,132 KB
testcase_38 AC 1,652 ms
88,420 KB
testcase_39 AC 1,640 ms
88,668 KB
testcase_40 AC 1,626 ms
88,512 KB
testcase_41 AC 1,638 ms
89,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
i3 = pow(3, MOD - 2, MOD)

"""pypy用行列累乗ライブラリは https://github.com/fujihiraryo/alogorithm-python/blob/master/integer/matrix.py から拝借しています。"""


def product(a, b, p=MOD):
    n = len(a)
    c = [[0] * n for i in range(n)]
    for i in range(n):
        for j in range(n):
            c[i][j] = sum([a[i][k] * b[k][j] for k in range(n)]) % p
    return c


def matpow(a, k, p=MOD):
    if k == 1:
        return a
    if k % 2 == 0:
        b = matpow(a, k // 2)
        return product(b, b, p=p)
    return product(a, matpow(a, k - 1), p=p)


def solve(N):
    x = [1, 0, 0, 0, 0, 0]
    A = [[i3, 0, 0, 0, i3, i3],
         [0, i3, 0, i3, 0, i3],
         [0, 0, i3, i3, i3, 0],
         [1, 0, 0, 0, 0, 0],
         [0, 1, 0, 0, 0, 0],
         [0, 0, 1, 0, 0, 0]]
    return matpow(A, N)[0][0]


T = int(input())
for _ in range(T):
    print(solve(int(input())))
0