結果

問題 No.1073 無限すごろく
コンテスト
ユーザー pluto77
提出日時 2020-06-12 10:46:01
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 638 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 344 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-10 01:50:55
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def mmul(A,B):
 res=[[0]*6 for i in range(6)]
 for i in range(6):
  for k in range(6):
   for j in range(6):
    res[i][j]+=A[i][k]*B[k][j]
    res[i][j]%=mod
 return res

def mpow(A, n):
 res=[[0]*6 for i in range(6)]
 for i in range(6):
  res[i][i]=1
 while n:
  if n&1:
   res=mmul(res, A)
  A=mmul(A, A)
  n>>=1
 return res

mod=10**9+7
N=int(input())

p=[1]
for i in range(5):
 p.append(sum(p)*pow(6,mod-2,mod)%mod)
if N<6:
 print(p[N])
 exit()

A=[[0]*6 for i in range(6)]
for i in range(6):
 A[0][i] = p[1]
for i in range(1,6):
 A[i][i-1]=1
p.reverse()
x=mpow(A,N-5)
res=0
for i in range(6):
 res+=p[i]*x[0][i]
res%=mod
print(res)
0