結果

問題 No.314 ケンケンパ
ユーザー koyumeishikoyumeishi
提出日時 2015-12-07 00:56:46
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 79 ms / 1,000 ms
コード長 603 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 76,784 KB
最終ジャッジ日時 2023-10-12 18:44:19
合計ジャッジ時間 3,329 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,728 KB
testcase_01 AC 79 ms
76,276 KB
testcase_02 AC 78 ms
76,332 KB
testcase_03 AC 77 ms
76,360 KB
testcase_04 AC 79 ms
76,784 KB
testcase_05 AC 77 ms
76,276 KB
testcase_06 AC 78 ms
76,468 KB
testcase_07 AC 78 ms
76,600 KB
testcase_08 AC 79 ms
76,468 KB
testcase_09 AC 77 ms
76,264 KB
testcase_10 AC 78 ms
76,732 KB
testcase_11 AC 76 ms
76,440 KB
testcase_12 AC 76 ms
76,580 KB
testcase_13 AC 76 ms
76,632 KB
testcase_14 AC 77 ms
76,140 KB
testcase_15 AC 76 ms
76,276 KB
testcase_16 AC 76 ms
76,272 KB
testcase_17 AC 77 ms
76,660 KB
testcase_18 AC 76 ms
76,436 KB
testcase_19 AC 78 ms
76,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = 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