結果

問題 No.1136 Four Points Tour
ユーザー 双六
提出日時 2020-08-05 22:50:56
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 658 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 67,020 KB
最終ジャッジ日時 2024-09-17 19:53:48
合計ジャッジ時間 3,564 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

# 行列累乗 NumPy用
import numpy as np

mod = 10 ** 9 + 7
def matrixPow(A, n, N):
	B = np.identity(N, dtype = np.int)
	while n > 0:
		if n & 1 == 1:
			B = (A @ B) % mod
		A = (A @ A) % mod
		n >>= 1
	return B


#処理内容
def main():
	N = int(input())
	A = np.array([[0, 1, 1, 1],[1, 0, 1, 1],[1, 1, 0, 1],[1, 1, 1, 0]])
	mat = matrixPow(A, N, 4)
	ans = mat @ np.array([[0], [0], [0], [1]])
	print(ans[3, 0])

if __name__ == '__main__':
	main()
0