結果

問題 No.1704 Many Bus Stops (easy)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:06:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,802 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 572 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 93,032 KB
最終ジャッジ日時 2023-09-30 12:34:45
合計ジャッジ時間 52,390 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
76,576 KB
testcase_01 AC 1,739 ms
88,952 KB
testcase_02 AC 623 ms
79,960 KB
testcase_03 AC 605 ms
80,392 KB
testcase_04 AC 626 ms
80,732 KB
testcase_05 AC 625 ms
79,908 KB
testcase_06 AC 626 ms
80,536 KB
testcase_07 AC 637 ms
79,540 KB
testcase_08 AC 627 ms
80,448 KB
testcase_09 AC 624 ms
79,384 KB
testcase_10 AC 625 ms
81,260 KB
testcase_11 AC 631 ms
79,336 KB
testcase_12 AC 639 ms
79,584 KB
testcase_13 AC 647 ms
81,728 KB
testcase_14 AC 631 ms
80,260 KB
testcase_15 AC 641 ms
78,948 KB
testcase_16 AC 624 ms
79,384 KB
testcase_17 AC 629 ms
79,384 KB
testcase_18 AC 642 ms
80,476 KB
testcase_19 AC 628 ms
79,452 KB
testcase_20 AC 624 ms
79,844 KB
testcase_21 AC 629 ms
79,224 KB
testcase_22 AC 1,740 ms
90,672 KB
testcase_23 AC 1,801 ms
89,084 KB
testcase_24 AC 1,785 ms
93,032 KB
testcase_25 AC 1,752 ms
89,552 KB
testcase_26 AC 1,745 ms
89,908 KB
testcase_27 AC 1,782 ms
90,892 KB
testcase_28 AC 1,766 ms
89,704 KB
testcase_29 AC 1,793 ms
88,772 KB
testcase_30 AC 1,796 ms
89,676 KB
testcase_31 AC 1,767 ms
90,260 KB
testcase_32 AC 1,775 ms
90,184 KB
testcase_33 AC 1,771 ms
90,976 KB
testcase_34 AC 1,774 ms
92,144 KB
testcase_35 AC 1,734 ms
90,180 KB
testcase_36 AC 1,764 ms
88,876 KB
testcase_37 AC 1,754 ms
90,716 KB
testcase_38 AC 1,763 ms
88,636 KB
testcase_39 AC 1,770 ms
90,492 KB
testcase_40 AC 1,802 ms
91,692 KB
testcase_41 AC 1,801 ms
91,028 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