結果

問題 No.1704 Many Bus Stops (easy)
ユーザー rin204rin204
提出日時 2022-01-23 01:39:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 605 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 92,352 KB
最終ジャッジ日時 2024-05-06 08:36:03
合計ジャッジ時間 19,844 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
62,720 KB
testcase_01 AC 564 ms
91,328 KB
testcase_02 AC 290 ms
82,844 KB
testcase_03 AC 301 ms
82,852 KB
testcase_04 AC 290 ms
82,740 KB
testcase_05 AC 294 ms
82,412 KB
testcase_06 AC 299 ms
82,416 KB
testcase_07 AC 289 ms
82,276 KB
testcase_08 AC 285 ms
82,740 KB
testcase_09 AC 292 ms
83,052 KB
testcase_10 AC 295 ms
82,400 KB
testcase_11 AC 299 ms
82,392 KB
testcase_12 AC 293 ms
82,528 KB
testcase_13 AC 290 ms
83,088 KB
testcase_14 AC 285 ms
82,420 KB
testcase_15 AC 305 ms
82,372 KB
testcase_16 AC 322 ms
82,464 KB
testcase_17 AC 317 ms
82,708 KB
testcase_18 AC 314 ms
82,544 KB
testcase_19 AC 297 ms
82,644 KB
testcase_20 AC 300 ms
83,040 KB
testcase_21 AC 296 ms
83,016 KB
testcase_22 AC 570 ms
91,796 KB
testcase_23 AC 579 ms
91,408 KB
testcase_24 AC 597 ms
91,640 KB
testcase_25 AC 578 ms
91,072 KB
testcase_26 AC 568 ms
91,036 KB
testcase_27 AC 587 ms
91,068 KB
testcase_28 AC 575 ms
90,816 KB
testcase_29 AC 566 ms
91,888 KB
testcase_30 AC 605 ms
91,588 KB
testcase_31 AC 566 ms
91,272 KB
testcase_32 AC 567 ms
92,352 KB
testcase_33 AC 549 ms
91,016 KB
testcase_34 AC 570 ms
90,896 KB
testcase_35 AC 572 ms
91,016 KB
testcase_36 AC 568 ms
91,208 KB
testcase_37 AC 593 ms
91,596 KB
testcase_38 AC 573 ms
91,392 KB
testcase_39 AC 569 ms
91,664 KB
testcase_40 AC 565 ms
92,048 KB
testcase_41 AC 562 ms
91,544 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