結果

問題 No.314 ケンケンパ
ユーザー koyumeishikoyumeishi
提出日時 2015-12-07 00:57:23
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 609 bytes
コンパイル時間 929 ms
コンパイル使用メモリ 77,288 KB
実行使用メモリ 76,644 KB
最終ジャッジ日時 2023-10-12 18:44:25
合計ジャッジ時間 3,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,584 KB
testcase_01 AC 75 ms
76,140 KB
testcase_02 AC 75 ms
76,184 KB
testcase_03 AC 75 ms
76,016 KB
testcase_04 AC 74 ms
76,528 KB
testcase_05 AC 74 ms
76,308 KB
testcase_06 AC 75 ms
76,020 KB
testcase_07 AC 74 ms
76,472 KB
testcase_08 AC 76 ms
76,644 KB
testcase_09 AC 74 ms
76,128 KB
testcase_10 AC 76 ms
76,264 KB
testcase_11 AC 74 ms
76,484 KB
testcase_12 AC 75 ms
76,528 KB
testcase_13 AC 74 ms
76,400 KB
testcase_14 AC 75 ms
76,284 KB
testcase_15 AC 73 ms
76,456 KB
testcase_16 AC 75 ms
76,292 KB
testcase_17 AC 78 ms
76,148 KB
testcase_18 AC 75 ms
76,476 KB
testcase_19 AC 76 ms
76,308 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