結果

問題 No.1704 Many Bus Stops (easy)
ユーザー 👑 rin204rin204
提出日時 2022-01-23 01:39:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 95,036 KB
最終ジャッジ日時 2023-08-19 01:26:54
合計ジャッジ時間 19,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,348 KB
testcase_01 AC 515 ms
92,876 KB
testcase_02 AC 280 ms
84,508 KB
testcase_03 AC 278 ms
84,344 KB
testcase_04 AC 292 ms
84,548 KB
testcase_05 AC 284 ms
84,972 KB
testcase_06 AC 282 ms
85,596 KB
testcase_07 AC 296 ms
84,952 KB
testcase_08 AC 282 ms
84,580 KB
testcase_09 AC 281 ms
84,480 KB
testcase_10 AC 282 ms
85,572 KB
testcase_11 AC 283 ms
84,644 KB
testcase_12 AC 278 ms
84,988 KB
testcase_13 AC 280 ms
84,816 KB
testcase_14 AC 286 ms
85,400 KB
testcase_15 AC 286 ms
84,788 KB
testcase_16 AC 290 ms
84,668 KB
testcase_17 AC 311 ms
84,684 KB
testcase_18 AC 280 ms
85,748 KB
testcase_19 AC 278 ms
85,020 KB
testcase_20 AC 274 ms
84,912 KB
testcase_21 AC 278 ms
84,716 KB
testcase_22 AC 499 ms
94,008 KB
testcase_23 AC 497 ms
93,656 KB
testcase_24 AC 509 ms
93,908 KB
testcase_25 AC 509 ms
94,192 KB
testcase_26 AC 500 ms
93,600 KB
testcase_27 AC 506 ms
93,680 KB
testcase_28 AC 502 ms
95,036 KB
testcase_29 AC 503 ms
93,700 KB
testcase_30 AC 533 ms
93,336 KB
testcase_31 AC 500 ms
93,612 KB
testcase_32 AC 508 ms
93,696 KB
testcase_33 AC 503 ms
92,864 KB
testcase_34 AC 502 ms
92,488 KB
testcase_35 AC 526 ms
93,492 KB
testcase_36 AC 525 ms
93,624 KB
testcase_37 AC 529 ms
92,812 KB
testcase_38 AC 512 ms
93,892 KB
testcase_39 AC 515 ms
93,968 KB
testcase_40 AC 551 ms
94,152 KB
testcase_41 AC 520 ms
93,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from copy import deepcopy
MOD = 10 ** 9 + 7

def solve():
    n = int(input())
    m = 3
    inv = pow(m, MOD - 2, MOD) % MOD
    # A_i, A_{i-1}, B_i, B_{i-1}
    B = [inv, 1, 0, 0]
    A = [[inv, 0, 0, inv],
         [1, 0, 0, 0],
         [0, (m - 1) * inv, inv, (m - 2) * inv],
         [0, 0, 1, 0]]
    n -= 1
    while n:
        if n & 1:
            C = [0] * 4
            for i in range(4):
                for j in range(4):
                    C[i] += A[i][j] * B[j]
                C[i] %= MOD
            B = C.copy()
        n >>= 1
        C = [[0] * 4 for _ in range(4)]
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    C[i][j] += A[i][k] * A[k][j]
                C[i][j] %= MOD
        A = deepcopy(C)
    print(B[0])
    
    
    
for _ in range(int(input())):
    solve()
0