結果

問題 No.1704 Many Bus Stops (easy)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 23:04:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,725 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 92,692 KB
最終ジャッジ日時 2023-09-30 12:27:19
合計ジャッジ時間 49,455 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
76,328 KB
testcase_01 AC 1,557 ms
88,804 KB
testcase_02 AC 560 ms
80,264 KB
testcase_03 AC 573 ms
80,004 KB
testcase_04 AC 589 ms
80,624 KB
testcase_05 AC 600 ms
80,084 KB
testcase_06 AC 593 ms
80,604 KB
testcase_07 AC 593 ms
79,996 KB
testcase_08 AC 614 ms
80,220 KB
testcase_09 AC 596 ms
79,340 KB
testcase_10 AC 592 ms
81,308 KB
testcase_11 AC 623 ms
80,136 KB
testcase_12 AC 601 ms
79,848 KB
testcase_13 AC 622 ms
82,004 KB
testcase_14 AC 614 ms
80,476 KB
testcase_15 AC 600 ms
79,260 KB
testcase_16 AC 602 ms
79,576 KB
testcase_17 AC 595 ms
79,672 KB
testcase_18 AC 623 ms
81,304 KB
testcase_19 AC 615 ms
80,080 KB
testcase_20 AC 597 ms
80,196 KB
testcase_21 AC 579 ms
79,248 KB
testcase_22 AC 1,636 ms
91,160 KB
testcase_23 AC 1,631 ms
89,120 KB
testcase_24 AC 1,620 ms
92,692 KB
testcase_25 AC 1,638 ms
89,892 KB
testcase_26 AC 1,608 ms
89,992 KB
testcase_27 AC 1,725 ms
90,704 KB
testcase_28 AC 1,690 ms
89,876 KB
testcase_29 AC 1,655 ms
89,164 KB
testcase_30 AC 1,681 ms
89,812 KB
testcase_31 AC 1,676 ms
90,732 KB
testcase_32 AC 1,587 ms
90,856 KB
testcase_33 AC 1,642 ms
91,276 KB
testcase_34 AC 1,642 ms
92,296 KB
testcase_35 AC 1,711 ms
90,304 KB
testcase_36 AC 1,637 ms
88,752 KB
testcase_37 AC 1,722 ms
90,868 KB
testcase_38 AC 1,708 ms
88,568 KB
testcase_39 AC 1,664 ms
90,708 KB
testcase_40 AC 1,722 ms
91,564 KB
testcase_41 AC 1,664 ms
91,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
i3 = pow(3, -1, 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=10 ** 9 + 7):
    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