結果

問題 No.1704 Many Bus Stops (easy)
ユーザー irumo8202irumo8202
提出日時 2022-01-29 17:46:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 327 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 29,720 KB
最終ジャッジ日時 2023-08-30 17:36:32
合計ジャッジ時間 15,541 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
29,632 KB
testcase_01 AC 296 ms
29,572 KB
testcase_02 AC 218 ms
29,556 KB
testcase_03 AC 228 ms
29,572 KB
testcase_04 AC 228 ms
29,496 KB
testcase_05 AC 225 ms
29,596 KB
testcase_06 AC 228 ms
29,536 KB
testcase_07 AC 221 ms
29,600 KB
testcase_08 AC 216 ms
29,620 KB
testcase_09 AC 220 ms
29,504 KB
testcase_10 AC 220 ms
29,540 KB
testcase_11 AC 221 ms
29,524 KB
testcase_12 AC 213 ms
29,552 KB
testcase_13 AC 215 ms
29,448 KB
testcase_14 AC 220 ms
29,568 KB
testcase_15 AC 218 ms
29,572 KB
testcase_16 AC 217 ms
29,516 KB
testcase_17 AC 216 ms
29,572 KB
testcase_18 AC 210 ms
29,548 KB
testcase_19 AC 226 ms
29,436 KB
testcase_20 AC 213 ms
29,544 KB
testcase_21 AC 219 ms
29,572 KB
testcase_22 AC 306 ms
29,604 KB
testcase_23 AC 317 ms
29,524 KB
testcase_24 AC 314 ms
29,592 KB
testcase_25 AC 317 ms
29,584 KB
testcase_26 AC 314 ms
29,572 KB
testcase_27 AC 310 ms
29,584 KB
testcase_28 AC 312 ms
29,592 KB
testcase_29 AC 314 ms
29,664 KB
testcase_30 AC 313 ms
29,492 KB
testcase_31 AC 322 ms
29,572 KB
testcase_32 AC 327 ms
29,656 KB
testcase_33 AC 313 ms
29,688 KB
testcase_34 AC 317 ms
29,584 KB
testcase_35 AC 315 ms
29,572 KB
testcase_36 AC 312 ms
29,592 KB
testcase_37 AC 315 ms
29,564 KB
testcase_38 AC 316 ms
29,532 KB
testcase_39 AC 318 ms
29,720 KB
testcase_40 AC 307 ms
29,600 KB
testcase_41 AC 312 ms
29,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

T = int(input())
MOD = 10 ** 9 + 7

M = np.array(
    [
        [1, 0, 0, 0, 1, 1],
        [0, 1, 0, 1, 0, 1],
        [0, 0, 1, 1, 1, 0],
        [3, 0, 0, 0, 0, 0],
        [0, 3, 0, 0, 0, 0],
        [0, 0, 3, 0, 0, 0],
    ]
)

doubling = [M]
for i in range(40):
    doubling.append(doubling[-1] @ doubling[-1])
    doubling[-1] = np.mod(doubling[-1], MOD)

fraction = pow(3, MOD - 2, MOD)

for _ in range(T):
    N = int(input())
    V = np.array([1, 0, 0, 3, 0, 0])

    for i in range(40)[::-1]:
        if N >> i & 1:
            V = doubling[i] @ V
            V = np.mod(V, MOD)

    print(V[3] * pow(fraction, N + 1, MOD) % MOD)
0