結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
76,188 KB
testcase_01 AC 167 ms
78,740 KB
testcase_02 AC 169 ms
78,244 KB
testcase_03 AC 150 ms
78,304 KB
testcase_04 AC 156 ms
77,992 KB
testcase_05 AC 152 ms
77,916 KB
testcase_06 AC 160 ms
78,272 KB
testcase_07 AC 159 ms
78,244 KB
testcase_08 AC 162 ms
78,152 KB
testcase_09 AC 166 ms
78,432 KB
testcase_10 AC 160 ms
78,468 KB
testcase_11 AC 161 ms
78,024 KB
testcase_12 AC 161 ms
78,216 KB
testcase_13 AC 151 ms
78,132 KB
testcase_14 AC 159 ms
78,352 KB
testcase_15 AC 160 ms
78,472 KB
testcase_16 AC 158 ms
78,216 KB
testcase_17 AC 159 ms
78,240 KB
testcase_18 AC 157 ms
78,188 KB
testcase_19 AC 156 ms
78,192 KB
testcase_20 AC 150 ms
77,916 KB
testcase_21 AC 162 ms
78,188 KB
testcase_22 AC 174 ms
78,544 KB
testcase_23 AC 173 ms
78,612 KB
testcase_24 AC 176 ms
78,540 KB
testcase_25 AC 172 ms
78,436 KB
testcase_26 AC 197 ms
78,672 KB
testcase_27 AC 176 ms
78,352 KB
testcase_28 AC 187 ms
78,380 KB
testcase_29 AC 185 ms
78,424 KB
testcase_30 AC 175 ms
78,560 KB
testcase_31 AC 176 ms
78,360 KB
testcase_32 AC 175 ms
78,496 KB
testcase_33 AC 177 ms
78,516 KB
testcase_34 AC 186 ms
78,388 KB
testcase_35 AC 174 ms
78,520 KB
testcase_36 AC 177 ms
78,568 KB
testcase_37 AC 176 ms
78,452 KB
testcase_38 AC 184 ms
78,348 KB
testcase_39 AC 174 ms
78,352 KB
testcase_40 AC 173 ms
78,448 KB
testcase_41 AC 177 ms
78,444 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