結果

問題 No.1704 Many Bus Stops (easy)
ユーザー H3PO4H3PO4
提出日時 2021-10-08 22:55:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 742 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 29,944 KB
最終ジャッジ日時 2023-09-30 12:07:58
合計ジャッジ時間 6,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
29,844 KB
testcase_01 TLE -
testcase_02 AC 1,059 ms
29,740 KB
testcase_03 AC 1,048 ms
29,832 KB
testcase_04 AC 1,030 ms
29,792 KB
testcase_05 AC 1,040 ms
29,820 KB
testcase_06 AC 1,038 ms
29,780 KB
testcase_07 AC 1,044 ms
29,824 KB
testcase_08 AC 1,052 ms
29,788 KB
testcase_09 AC 1,046 ms
29,900 KB
testcase_10 AC 1,037 ms
29,832 KB
testcase_11 AC 1,050 ms
29,732 KB
testcase_12 AC 1,047 ms
29,804 KB
testcase_13 AC 1,025 ms
29,832 KB
testcase_14 AC 1,053 ms
29,788 KB
testcase_15 AC 1,055 ms
29,848 KB
testcase_16 AC 1,049 ms
29,792 KB
testcase_17 AC 1,043 ms
29,944 KB
testcase_18 AC 1,051 ms
29,656 KB
testcase_19 AC 1,063 ms
29,756 KB
testcase_20 AC 1,046 ms
29,916 KB
testcase_21 AC 1,033 ms
29,752 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

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


def pow_matrix_mod(x, n, mod=MOD):
    if not n:
        return np.eye(len(x), dtype=object)
    if n % 2 == 0:
        return pow_matrix_mod(x @ x % mod, n // 2) % mod
    else:
        return x @ pow_matrix_mod(x @ x % mod, (n - 1) // 2) % mod


def solve(N):
    x = np.array([1, 0, 0, 0, 0, 0], dtype=object)
    A = np.array([[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]], dtype=object)
    return (x @ pow_matrix_mod(A, N))[0] % MOD


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