結果

問題 No.314 ケンケンパ
ユーザー koyumeishikoyumeishi
提出日時 2015-12-07 00:58:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 609 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 6,644 KB
実行使用メモリ 6,192 KB
最終ジャッジ日時 2023-10-12 18:44:28
合計ジャッジ時間 1,608 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,192 KB
testcase_01 AC 12 ms
5,980 KB
testcase_02 AC 11 ms
6,120 KB
testcase_03 AC 12 ms
5,980 KB
testcase_04 AC 11 ms
6,072 KB
testcase_05 AC 12 ms
6,000 KB
testcase_06 AC 12 ms
5,992 KB
testcase_07 AC 12 ms
5,980 KB
testcase_08 AC 12 ms
5,988 KB
testcase_09 AC 12 ms
6,004 KB
testcase_10 AC 12 ms
6,188 KB
testcase_11 AC 12 ms
6,052 KB
testcase_12 AC 12 ms
6,056 KB
testcase_13 AC 12 ms
6,104 KB
testcase_14 AC 12 ms
5,952 KB
testcase_15 AC 12 ms
6,184 KB
testcase_16 AC 12 ms
6,052 KB
testcase_17 AC 13 ms
5,968 KB
testcase_18 AC 12 ms
6,132 KB
testcase_19 AC 12 ms
5,992 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 xrange(3) :
			for k in xrange(3) :
				for j in xrange(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 xrange(3) :
		for k in xrange(3) :
			for j in xrange(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