結果

問題 No.1136 Four Points Tour
ユーザー flippergo
提出日時 2020-12-24 14:01:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 488 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,212 KB
最終ジャッジ日時 2024-09-21 16:54:55
合計ジャッジ時間 11,025 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 TLE * 2 -- * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
p = 10**9+7
I = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],dtype=np.int64)
def pow(A,n):
    if n==0:
        return I
    if n==1:
        return A
    if n%2==0:
        return (np.matmul(pow(A,n//2),pow(A,n//2)))%p
    else:
        return np.matmul(A,np.matmul(pow(A,(n-1)//2),pow(A,(n-1)//2))%p)%p
A = np.array([[0,1,1,1],[1,0,1,1],[1,1,0,1],[1,1,1,0]],dtype=np.int64)
N = int(input())
a = np.matmul(np.array([1,0,0,0],dtype=np.int64),pow(A,N))
print(a[0])
0