結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー しらっ亭しらっ亭
提出日時 2017-12-08 18:24:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 93 ms / 3,000 ms
コード長 905 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 8,388 KB
最終ジャッジ日時 2023-08-19 22:37:03
合計ジャッジ時間 6,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,232 KB
testcase_01 AC 19 ms
8,208 KB
testcase_02 AC 17 ms
8,328 KB
testcase_03 AC 15 ms
8,292 KB
testcase_04 AC 16 ms
8,284 KB
testcase_05 AC 15 ms
8,284 KB
testcase_06 AC 16 ms
8,256 KB
testcase_07 AC 16 ms
8,232 KB
testcase_08 AC 16 ms
8,192 KB
testcase_09 AC 15 ms
8,376 KB
testcase_10 AC 16 ms
8,160 KB
testcase_11 AC 16 ms
8,380 KB
testcase_12 AC 21 ms
8,292 KB
testcase_13 AC 23 ms
8,292 KB
testcase_14 AC 27 ms
8,364 KB
testcase_15 AC 30 ms
8,232 KB
testcase_16 AC 34 ms
8,216 KB
testcase_17 AC 35 ms
8,192 KB
testcase_18 AC 40 ms
8,292 KB
testcase_19 AC 42 ms
8,312 KB
testcase_20 AC 47 ms
8,384 KB
testcase_21 AC 46 ms
8,176 KB
testcase_22 AC 53 ms
8,332 KB
testcase_23 AC 54 ms
8,232 KB
testcase_24 AC 61 ms
8,240 KB
testcase_25 AC 63 ms
8,376 KB
testcase_26 AC 66 ms
8,200 KB
testcase_27 AC 72 ms
8,204 KB
testcase_28 AC 72 ms
8,336 KB
testcase_29 AC 76 ms
8,240 KB
testcase_30 AC 73 ms
8,260 KB
testcase_31 AC 70 ms
8,260 KB
testcase_32 AC 69 ms
8,276 KB
testcase_33 AC 75 ms
8,228 KB
testcase_34 AC 73 ms
8,252 KB
testcase_35 AC 70 ms
8,184 KB
testcase_36 AC 72 ms
8,196 KB
testcase_37 AC 76 ms
8,260 KB
testcase_38 AC 79 ms
8,308 KB
testcase_39 AC 79 ms
8,368 KB
testcase_40 AC 79 ms
8,256 KB
testcase_41 AC 78 ms
8,228 KB
testcase_42 AC 77 ms
8,288 KB
testcase_43 AC 78 ms
8,260 KB
testcase_44 AC 78 ms
8,260 KB
testcase_45 AC 78 ms
8,176 KB
testcase_46 AC 78 ms
8,204 KB
testcase_47 AC 78 ms
8,284 KB
testcase_48 AC 79 ms
8,300 KB
testcase_49 AC 78 ms
8,324 KB
testcase_50 AC 78 ms
8,200 KB
testcase_51 AC 78 ms
8,340 KB
testcase_52 AC 79 ms
8,164 KB
testcase_53 AC 78 ms
8,376 KB
testcase_54 AC 78 ms
8,316 KB
testcase_55 AC 79 ms
8,284 KB
testcase_56 AC 79 ms
8,332 KB
testcase_57 AC 78 ms
8,332 KB
testcase_58 AC 78 ms
8,204 KB
testcase_59 AC 91 ms
8,344 KB
testcase_60 AC 90 ms
8,244 KB
testcase_61 AC 90 ms
8,312 KB
testcase_62 AC 93 ms
8,228 KB
testcase_63 AC 91 ms
8,388 KB
testcase_64 AC 90 ms
8,204 KB
testcase_65 AC 90 ms
8,284 KB
testcase_66 AC 89 ms
8,236 KB
testcase_67 AC 91 ms
8,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# OEIS 解です!

mod = 10 ** 9 + 7


def mat_mul(l, r):
	ret = [[0] * 15 for _ in range(15)]
	for i in range(15):
		reti = ret[i]
		li = l[i]
		for k in range(15):
			lik = li[k]
			rk = r[k]
			for j in range(15):
				reti[j] += (lik * rk[j])
				reti[j] %= mod
	return ret


def mat_pow(A, m):
	B = [[0] * 15 for _ in range(15)]

	for i in range(15):
		B[i][i] = 1

	while m:
		if m & 1:
			B = mat_mul(B, A)
		A = mat_mul(A, A)
		m >>= 1
	return B


def solve(n):
	anss = [0, 2, 5, 22, 75, 264, 941, 3286, 11623, 40960, 144267, 508812, 1792981, 6319994, 22277291, 78518760]

	if n <= 15:
		return anss[n]

	A = [[0] * 15 for _ in range(15)]
	A[0] = [1, 5, 11, 5, 14, 8, 3, 0, -5 + mod, -11 + mod, -1 + mod, 2, 0, 0, 1]
	for i in range(1, 15):
		A[i][i-1] = 1

	A = mat_pow(A, n-15)

	ans = 0
	for i in range(15):
		ans += A[0][i] * anss[15-i]
		ans %= mod

	return ans


print(solve(int(input())))
0