結果

問題 No.314 ケンケンパ
ユーザー koyumeishikoyumeishi
提出日時 2015-12-07 01:00:23
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 18 ms / 1,000 ms
コード長 608 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-10-12 18:44:38
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,020 KB
testcase_01 AC 16 ms
8,168 KB
testcase_02 AC 16 ms
8,184 KB
testcase_03 AC 16 ms
7,780 KB
testcase_04 AC 16 ms
8,296 KB
testcase_05 AC 16 ms
8,204 KB
testcase_06 AC 16 ms
8,144 KB
testcase_07 AC 16 ms
8,300 KB
testcase_08 AC 16 ms
8,160 KB
testcase_09 AC 16 ms
8,320 KB
testcase_10 AC 16 ms
8,216 KB
testcase_11 AC 16 ms
8,172 KB
testcase_12 AC 17 ms
8,240 KB
testcase_13 AC 15 ms
7,816 KB
testcase_14 AC 16 ms
8,204 KB
testcase_15 AC 16 ms
8,240 KB
testcase_16 AC 16 ms
8,212 KB
testcase_17 AC 16 ms
8,276 KB
testcase_18 AC 16 ms
8,176 KB
testcase_19 AC 17 ms
8,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
mat = [[0,0,1],[1,0,0],[1,1,0]]

mod = 1000000007

ret = [[1,0,0],[0,1,0],[0,0,1]]
while n>0 :
	if (n&1) == 1 :
		tmp = [[0,0,0],[0,0,0],[0,0,0]]
		for i in range(3) :
			for k in range(3) :
				for j in range(3) :
					tmp[i][j] += ret[i][k] * mat[k][j]
					if tmp[i][j] >= mod :
						tmp[i][j] %= mod
		ret = tmp

	tmp_ = [[0,0,0],[0,0,0],[0,0,0]]
	for i in range(3) :
		for k in range(3) :
			for j in range(3) :
				tmp_[i][j] += mat[i][k] * mat[k][j]
				if tmp_[i][j] >= mod :
					tmp_[i][j] %= mod
	mat = tmp_

	n = n>>1

ans = (ret[0][2] + ret[1][2] + ret[2][2]) % mod

print(ans)
0