結果

問題 No.1704 Many Bus Stops (easy)
ユーザー titiatitia
提出日時 2021-10-09 05:33:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 78,640 KB
最終ジャッジ日時 2023-09-30 22:21:54
合計ジャッジ時間 9,760 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
76,156 KB
testcase_01 AC 167 ms
78,640 KB
testcase_02 AC 170 ms
78,220 KB
testcase_03 AC 161 ms
78,240 KB
testcase_04 AC 164 ms
77,756 KB
testcase_05 AC 163 ms
77,920 KB
testcase_06 AC 167 ms
78,132 KB
testcase_07 AC 165 ms
78,132 KB
testcase_08 AC 170 ms
78,016 KB
testcase_09 AC 167 ms
78,008 KB
testcase_10 AC 167 ms
78,424 KB
testcase_11 AC 167 ms
78,220 KB
testcase_12 AC 168 ms
78,012 KB
testcase_13 AC 159 ms
77,700 KB
testcase_14 AC 169 ms
78,460 KB
testcase_15 AC 171 ms
78,012 KB
testcase_16 AC 169 ms
78,032 KB
testcase_17 AC 169 ms
78,016 KB
testcase_18 AC 169 ms
78,180 KB
testcase_19 AC 169 ms
77,876 KB
testcase_20 AC 159 ms
77,712 KB
testcase_21 AC 170 ms
78,024 KB
testcase_22 AC 187 ms
78,196 KB
testcase_23 AC 186 ms
78,256 KB
testcase_24 AC 186 ms
78,376 KB
testcase_25 AC 183 ms
78,240 KB
testcase_26 AC 206 ms
78,304 KB
testcase_27 AC 184 ms
78,336 KB
testcase_28 AC 183 ms
78,320 KB
testcase_29 AC 186 ms
78,244 KB
testcase_30 AC 186 ms
78,424 KB
testcase_31 AC 188 ms
78,212 KB
testcase_32 AC 185 ms
78,204 KB
testcase_33 AC 185 ms
78,436 KB
testcase_34 AC 196 ms
78,516 KB
testcase_35 AC 182 ms
78,232 KB
testcase_36 AC 182 ms
78,400 KB
testcase_37 AC 181 ms
78,080 KB
testcase_38 AC 189 ms
78,136 KB
testcase_39 AC 180 ms
78,172 KB
testcase_40 AC 174 ms
78,204 KB
testcase_41 AC 179 ms
78,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7

# 行列の計算(numpyを使えないとき,modを使用)
def prod(A,B,k,l,m):# A:k*l,B:l*m
    C=[[None for i in range(m)] for j in range(k)]

    for i in range(k):
        for j in range(m):
            ANS=0
            for pl in range(l):
                ANS=(ANS+A[i][pl]*B[pl][j])%mod

            C[i][j]=ANS

    return C

def plus(A,B,k,l):# a,B:k*l
    C=[[None for i in range(l)] for j in range(k)]

    for i in range(k):
        for j in range(l):
            C[i][j]=(A[i][j]+B[i][j])%mod

    return C

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

A=[[0]*6 for i in range(6)]
A[0][0]=INV
A[0][4]=INV
A[0][5]=INV

A[1][1]=INV
A[1][3]=INV
A[1][5]=INV

A[2][2]=INV
A[2][3]=INV
A[2][4]=INV

A[3][0]=1
A[4][1]=1
A[5][2]=1

POWA=[A]
for i in range(60):
    POWA.append(prod(POWA[-1],POWA[-1],6,6,6)) # ベキを求めて

T=int(input())
for tests in range(T):
    n=int(input())

    X=[[1,0,0,0,0,0]]

    while n:
        X=prod(X,POWA[n.bit_length()-1],1,6,6) # n乗の場合
        n-=1<<(n.bit_length()-1)

    print(X[0][0])
    
0