結果

問題 No.1704 Many Bus Stops (easy)
ユーザー harurunharurun
提出日時 2021-09-10 22:39:29
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,006 ms / 2,000 ms
コード長 946 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,492 KB
実行使用メモリ 79,904 KB
最終ジャッジ日時 2023-09-30 09:28:29
合計ジャッジ時間 31,612 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
76,012 KB
testcase_01 AC 977 ms
79,468 KB
testcase_02 AC 436 ms
79,708 KB
testcase_03 AC 432 ms
79,240 KB
testcase_04 AC 433 ms
79,708 KB
testcase_05 AC 434 ms
79,552 KB
testcase_06 AC 434 ms
79,780 KB
testcase_07 AC 436 ms
79,244 KB
testcase_08 AC 442 ms
79,892 KB
testcase_09 AC 435 ms
79,592 KB
testcase_10 AC 433 ms
79,196 KB
testcase_11 AC 433 ms
78,768 KB
testcase_12 AC 433 ms
79,812 KB
testcase_13 AC 431 ms
79,620 KB
testcase_14 AC 436 ms
79,904 KB
testcase_15 AC 433 ms
78,964 KB
testcase_16 AC 432 ms
79,648 KB
testcase_17 AC 434 ms
79,428 KB
testcase_18 AC 430 ms
79,584 KB
testcase_19 AC 434 ms
79,436 KB
testcase_20 AC 435 ms
79,720 KB
testcase_21 AC 433 ms
79,464 KB
testcase_22 AC 997 ms
79,016 KB
testcase_23 AC 999 ms
78,360 KB
testcase_24 AC 995 ms
78,192 KB
testcase_25 AC 995 ms
78,152 KB
testcase_26 AC 992 ms
78,664 KB
testcase_27 AC 1,003 ms
78,636 KB
testcase_28 AC 1,001 ms
78,708 KB
testcase_29 AC 1,006 ms
78,376 KB
testcase_30 AC 994 ms
78,944 KB
testcase_31 AC 994 ms
78,260 KB
testcase_32 AC 992 ms
78,296 KB
testcase_33 AC 987 ms
78,636 KB
testcase_34 AC 991 ms
79,044 KB
testcase_35 AC 993 ms
78,648 KB
testcase_36 AC 990 ms
78,456 KB
testcase_37 AC 989 ms
78,624 KB
testcase_38 AC 988 ms
78,388 KB
testcase_39 AC 995 ms
78,124 KB
testcase_40 AC 992 ms
78,432 KB
testcase_41 AC 997 ms
78,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def matrix_exp(X,n,mod):
  Y=[[0]*len(X)for _ in[0]*len(X)]
  for i in range(len(X)):
    Y[i][i]=1
  while n>0:
    if n&1:
      Y=matrix_mul(Y,X,mod)
    X=matrix_mul(X,X,mod)
    n>>=1
  return Y

def calculate_nth(mod,n,A):
  A=matrix_exp(A,n,mod)
  res=matrix_mul(A,[[1],[0],[0],[3],[0],[0]],mod)
  return res[3][0]


def solve():
  mod=10**9+7
  N=int(pin())
  assert(1<=N<=10**9)
  A=[[1,0,0,0,1,1],[0,1,0,1,0,1],[0,0,1,1,1,0],[3,0,0,0,0,0],[0,3,0,0,0,0],[0,0,3,0,0,0]]
  ans=calculate_nth(mod,N,A)
  c=pow(pow(3,mod-2,mod),N+1,mod)
  # A にいる確率
  a=ans*c%mod
  print(a) 
  return

from sys import stdin
pin=stdin.readline
def main():
  T=int(pin())
  assert(1<=T<=3*10**3)
  for i in range(T):
    solve()
  return

main()
0