結果

問題 No.1704 Many Bus Stops (easy)
ユーザー tktk_snsntktk_snsn
提出日時 2021-10-08 22:59:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,514 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 81,256 KB
最終ジャッジ日時 2023-09-30 12:19:02
合計ジャッジ時間 45,625 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
76,584 KB
testcase_01 AC 1,473 ms
80,076 KB
testcase_02 AC 596 ms
79,728 KB
testcase_03 AC 603 ms
81,256 KB
testcase_04 AC 612 ms
80,520 KB
testcase_05 AC 598 ms
79,680 KB
testcase_06 AC 603 ms
80,192 KB
testcase_07 AC 606 ms
80,444 KB
testcase_08 AC 597 ms
80,168 KB
testcase_09 AC 603 ms
79,756 KB
testcase_10 AC 599 ms
80,004 KB
testcase_11 AC 596 ms
79,716 KB
testcase_12 AC 596 ms
80,204 KB
testcase_13 AC 598 ms
80,152 KB
testcase_14 AC 596 ms
80,616 KB
testcase_15 AC 597 ms
80,640 KB
testcase_16 AC 594 ms
80,348 KB
testcase_17 AC 597 ms
79,688 KB
testcase_18 AC 595 ms
79,644 KB
testcase_19 AC 597 ms
79,656 KB
testcase_20 AC 603 ms
79,524 KB
testcase_21 AC 595 ms
79,868 KB
testcase_22 AC 1,502 ms
79,008 KB
testcase_23 AC 1,499 ms
78,964 KB
testcase_24 AC 1,507 ms
79,044 KB
testcase_25 AC 1,507 ms
79,048 KB
testcase_26 AC 1,500 ms
79,164 KB
testcase_27 AC 1,514 ms
79,588 KB
testcase_28 AC 1,506 ms
79,308 KB
testcase_29 AC 1,514 ms
79,192 KB
testcase_30 AC 1,495 ms
78,872 KB
testcase_31 AC 1,507 ms
79,336 KB
testcase_32 AC 1,508 ms
78,988 KB
testcase_33 AC 1,509 ms
79,088 KB
testcase_34 AC 1,498 ms
78,912 KB
testcase_35 AC 1,511 ms
79,024 KB
testcase_36 AC 1,508 ms
79,516 KB
testcase_37 AC 1,499 ms
79,176 KB
testcase_38 AC 1,512 ms
79,432 KB
testcase_39 AC 1,498 ms
79,656 KB
testcase_40 AC 1,498 ms
79,888 KB
testcase_41 AC 1,502 ms
79,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
P = 333333336


def mat_mul(A, B):
    res = [[0] * len(B[0]) for _ in range(len(A))]
    for i in range(len(A)):
        for k in range(len(A[0])):
            for j in range(len(B[0])):
                res[i][j] += A[i][k] * B[k][j]
                res[i][j] %= mod
    return res


def mat_pow(A, n):
    size = len(A)
    res = [[0] * size for _ in range(size)]
    for i in range(size):
        res[i][i] = 1
    while n:
        if n & 1:
            res = mat_mul(res, A)
        A = mat_mul(A, A)
        n >>= 1
    return res


A = [[0] * 9 for _ in range(9)]
for i in range(0, 9, 3):
    A[i][i] = P
    A[i+1][i] = P
    A[i+2][i] = P

    A[(i+3) % 9][i+1] = 1
    A[(i+6) % 9][i+2] = 1

T = int(input())
for _ in range(T):
    N = int(input())
    B = mat_pow(A, N)
    print(B[0][0])
0