結果

問題 No.1704 Many Bus Stops (easy)
ユーザー chineristACchineristAC
提出日時 2021-09-12 01:04:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 86,652 KB
実行使用メモリ 80,868 KB
最終ジャッジ日時 2023-09-30 09:30:33
合計ジャッジ時間 18,273 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
75,904 KB
testcase_01 AC 464 ms
79,672 KB
testcase_02 AC 301 ms
78,168 KB
testcase_03 AC 302 ms
78,356 KB
testcase_04 AC 300 ms
78,604 KB
testcase_05 AC 304 ms
78,296 KB
testcase_06 AC 300 ms
78,508 KB
testcase_07 AC 304 ms
78,212 KB
testcase_08 AC 308 ms
78,132 KB
testcase_09 AC 326 ms
80,868 KB
testcase_10 AC 303 ms
78,644 KB
testcase_11 AC 311 ms
79,544 KB
testcase_12 AC 299 ms
78,776 KB
testcase_13 AC 310 ms
79,008 KB
testcase_14 AC 322 ms
79,868 KB
testcase_15 AC 309 ms
78,744 KB
testcase_16 AC 304 ms
78,344 KB
testcase_17 AC 304 ms
78,472 KB
testcase_18 AC 300 ms
78,608 KB
testcase_19 AC 300 ms
78,180 KB
testcase_20 AC 299 ms
78,604 KB
testcase_21 AC 310 ms
78,552 KB
testcase_22 AC 464 ms
78,524 KB
testcase_23 AC 479 ms
78,956 KB
testcase_24 AC 532 ms
79,008 KB
testcase_25 AC 471 ms
78,484 KB
testcase_26 AC 468 ms
79,452 KB
testcase_27 AC 468 ms
78,488 KB
testcase_28 AC 484 ms
78,816 KB
testcase_29 AC 476 ms
79,540 KB
testcase_30 AC 471 ms
79,100 KB
testcase_31 AC 472 ms
78,684 KB
testcase_32 AC 475 ms
79,228 KB
testcase_33 AC 475 ms
79,108 KB
testcase_34 AC 466 ms
79,428 KB
testcase_35 AC 479 ms
78,940 KB
testcase_36 AC 478 ms
79,208 KB
testcase_37 AC 461 ms
78,600 KB
testcase_38 AC 478 ms
78,724 KB
testcase_39 AC 471 ms
78,336 KB
testcase_40 AC 470 ms
79,064 KB
testcase_41 AC 456 ms
78,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9 + 7

def mat_mul(X,Y):
    n,m = len(X),len(Y[0])
    res = [[0 for j in range(m)] for i in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(len(Y)):
                res[i][j] += X[i][k] * Y[k][j]
                res[i][j] %= mod
    return res

i3 = pow(3,mod-2,mod)

A = [
[i3,0,0,i3],
[0,i3,2*i3,i3],
[1,0,0,0],
[0,1,0,0]
]

def solve(N):
    assert 1 <= N <= 10**9
    base = [[1],[0],[0],[0]]
    mat = [[int(i==j) for j in range(4)] for i in range(4)]
    tmp = [[A[i][j] for j in range(4)] for i in range(4)]
    while N:
        if N&1:
            mat = mat_mul(tmp,mat)
        tmp = mat_mul(tmp,tmp)
        N >>= 1
    base = mat_mul(mat,base)
    return base[0][0]

T = int(input())
assert 1 <= T <= 3000
for _ in range(T):
    print(solve(int(input())))
0