結果

問題 No.1704 Many Bus Stops (easy)
ユーザー tassei903tassei903
提出日時 2021-10-08 22:56:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 645 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 80,036 KB
最終ジャッジ日時 2023-09-30 12:09:43
合計ジャッジ時間 20,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,712 KB
testcase_01 AC 645 ms
78,440 KB
testcase_02 AC 298 ms
79,284 KB
testcase_03 AC 297 ms
79,484 KB
testcase_04 AC 298 ms
79,112 KB
testcase_05 AC 296 ms
79,364 KB
testcase_06 AC 293 ms
79,112 KB
testcase_07 AC 295 ms
79,680 KB
testcase_08 AC 297 ms
79,276 KB
testcase_09 AC 295 ms
79,544 KB
testcase_10 AC 298 ms
79,024 KB
testcase_11 AC 298 ms
79,404 KB
testcase_12 AC 300 ms
78,936 KB
testcase_13 AC 300 ms
79,728 KB
testcase_14 AC 298 ms
79,408 KB
testcase_15 AC 302 ms
79,932 KB
testcase_16 AC 295 ms
79,108 KB
testcase_17 AC 304 ms
79,604 KB
testcase_18 AC 301 ms
79,400 KB
testcase_19 AC 300 ms
80,036 KB
testcase_20 AC 299 ms
79,368 KB
testcase_21 AC 299 ms
79,972 KB
testcase_22 AC 588 ms
79,736 KB
testcase_23 AC 584 ms
79,476 KB
testcase_24 AC 586 ms
79,048 KB
testcase_25 AC 594 ms
78,752 KB
testcase_26 AC 584 ms
79,136 KB
testcase_27 AC 583 ms
79,172 KB
testcase_28 AC 587 ms
78,656 KB
testcase_29 AC 584 ms
79,620 KB
testcase_30 AC 594 ms
79,580 KB
testcase_31 AC 587 ms
79,116 KB
testcase_32 AC 587 ms
79,120 KB
testcase_33 AC 584 ms
79,500 KB
testcase_34 AC 588 ms
79,408 KB
testcase_35 AC 588 ms
78,960 KB
testcase_36 AC 586 ms
79,052 KB
testcase_37 AC 578 ms
79,768 KB
testcase_38 AC 582 ms
79,488 KB
testcase_39 AC 583 ms
78,360 KB
testcase_40 AC 577 ms
79,344 KB
testcase_41 AC 583 ms
78,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
sys.setrecursionlimit(10**7)
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################



#a*bの計算
def mat_mul(a,b):
    n,m,l=len(a),len(b[0]),len(b)
    c=[[0]*m for _ in range(n)]
    for i in range(n):
        for k in range(l):
            for  j in range(m):
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%mod
    return c
 
#a^nの計算
def mat_pow(a,n):
    m=len(a)
    b=[[0]*m for _ in range(m)]
    for i in range(m):
        b[i][i]=1
    while n>0:
        if n&1:
            b=mat_mul(b,a)
        a=mat_mul(a,a)
        n>>=1
    return b



t = ni()
p = mod = 10**9+7
z = pow(3,p-2,p)
s = list(zip([z,0,0,1,0,0]))
b = [[z,0,0,0,z,z],
     [0,z,0,z,0,z],
     [0,0,z,z,z,0],
     [1,0,0,0,0,0],
     [0,1,0,0,0,0],
     [0,0,1,0,0,0]]

for n in [ni() for i in range(t)]:
    if n==1:
        print(z)
    else:
        print(mat_mul(mat_pow(b,n-1),s)[0][0]%mod)
0