結果

問題 No.1704 Many Bus Stops (easy)
ユーザー mkawa2mkawa2
提出日時 2021-10-08 23:24:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,497 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 80,528 KB
最終ジャッジ日時 2023-09-30 13:23:45
合計ジャッジ時間 12,280 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
76,608 KB
testcase_01 AC 258 ms
79,212 KB
testcase_02 AC 196 ms
78,680 KB
testcase_03 AC 200 ms
78,672 KB
testcase_04 AC 196 ms
78,924 KB
testcase_05 AC 204 ms
78,468 KB
testcase_06 AC 202 ms
78,472 KB
testcase_07 AC 203 ms
78,524 KB
testcase_08 AC 197 ms
78,496 KB
testcase_09 AC 210 ms
78,516 KB
testcase_10 AC 199 ms
78,492 KB
testcase_11 AC 199 ms
78,384 KB
testcase_12 AC 205 ms
78,524 KB
testcase_13 AC 206 ms
78,556 KB
testcase_14 AC 205 ms
78,540 KB
testcase_15 AC 194 ms
78,332 KB
testcase_16 AC 199 ms
78,572 KB
testcase_17 AC 201 ms
78,844 KB
testcase_18 AC 203 ms
78,512 KB
testcase_19 AC 194 ms
78,288 KB
testcase_20 AC 206 ms
78,664 KB
testcase_21 AC 199 ms
78,472 KB
testcase_22 AC 295 ms
78,600 KB
testcase_23 AC 296 ms
78,892 KB
testcase_24 AC 294 ms
80,252 KB
testcase_25 AC 297 ms
79,128 KB
testcase_26 AC 289 ms
78,776 KB
testcase_27 AC 302 ms
78,920 KB
testcase_28 AC 291 ms
79,884 KB
testcase_29 AC 298 ms
79,052 KB
testcase_30 AC 296 ms
78,556 KB
testcase_31 AC 292 ms
79,900 KB
testcase_32 AC 294 ms
78,708 KB
testcase_33 AC 286 ms
80,164 KB
testcase_34 AC 287 ms
79,200 KB
testcase_35 AC 287 ms
78,648 KB
testcase_36 AC 295 ms
78,476 KB
testcase_37 AC 291 ms
79,008 KB
testcase_38 AC 294 ms
80,280 KB
testcase_39 AC 294 ms
80,528 KB
testcase_40 AC 296 ms
79,840 KB
testcase_41 AC 295 ms
78,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**19
# md = 998244353
md = 10**9+7

def dot(aa, bb):
    h = len(aa)
    w = len(bb[0])
    res = [[0]*w for _ in range(h)]
    for i, row in enumerate(aa):
        for j, col in enumerate(zip(*bb)):
            v = 0
            # for a, b in zip(row, col): v += a*b
            # res[i][j] = v%md
            for a, b in zip(row, col): v += a*b%md
            res[i][j] = v%md
    return res

def matpow(e):
    n = 4
    res = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    i = 0
    while e:
        if e & 1: res = dot(res, mm[i])
        e >>= 1
        i += 1
    return res

inv = pow(3, md-2, md)

mat = [[0, 0, 0, inv]
    , [0, 0, inv*2, inv]
    , [1, 0, inv, 0]
    , [0, 1, 0, inv]]

lim = 10**9+5

i = 1
mm = []
while i < lim:
    mm.append(mat)
    mat = dot(mat, mat)
    i <<= 1

for _ in range(II()):
    n = II()
    print(matpow(n)[2][2])
0