結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー しらっ亭しらっ亭
提出日時 2017-12-08 18:24:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 108 ms / 3,000 ms
コード長 905 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-07 05:39:48
合計ジャッジ時間 6,932 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 28 ms
10,624 KB
testcase_03 AC 27 ms
10,624 KB
testcase_04 AC 27 ms
10,624 KB
testcase_05 AC 27 ms
10,496 KB
testcase_06 AC 28 ms
10,496 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 27 ms
10,496 KB
testcase_09 AC 27 ms
10,752 KB
testcase_10 AC 27 ms
10,752 KB
testcase_11 AC 26 ms
10,624 KB
testcase_12 AC 32 ms
10,880 KB
testcase_13 AC 34 ms
10,496 KB
testcase_14 AC 39 ms
10,752 KB
testcase_15 AC 41 ms
10,752 KB
testcase_16 AC 45 ms
10,624 KB
testcase_17 AC 45 ms
10,624 KB
testcase_18 AC 51 ms
10,624 KB
testcase_19 AC 56 ms
10,752 KB
testcase_20 AC 59 ms
10,752 KB
testcase_21 AC 60 ms
10,624 KB
testcase_22 AC 67 ms
10,496 KB
testcase_23 AC 67 ms
10,880 KB
testcase_24 AC 73 ms
10,624 KB
testcase_25 AC 74 ms
10,752 KB
testcase_26 AC 80 ms
10,752 KB
testcase_27 AC 84 ms
10,880 KB
testcase_28 AC 87 ms
10,752 KB
testcase_29 AC 88 ms
10,496 KB
testcase_30 AC 84 ms
10,624 KB
testcase_31 AC 84 ms
10,624 KB
testcase_32 AC 81 ms
10,624 KB
testcase_33 AC 85 ms
10,624 KB
testcase_34 AC 87 ms
10,624 KB
testcase_35 AC 84 ms
10,624 KB
testcase_36 AC 87 ms
10,624 KB
testcase_37 AC 87 ms
10,880 KB
testcase_38 AC 90 ms
10,624 KB
testcase_39 AC 90 ms
10,624 KB
testcase_40 AC 92 ms
10,496 KB
testcase_41 AC 89 ms
10,880 KB
testcase_42 AC 91 ms
10,752 KB
testcase_43 AC 88 ms
10,624 KB
testcase_44 AC 96 ms
10,880 KB
testcase_45 AC 93 ms
10,752 KB
testcase_46 AC 90 ms
10,752 KB
testcase_47 AC 90 ms
10,752 KB
testcase_48 AC 89 ms
10,624 KB
testcase_49 AC 90 ms
10,752 KB
testcase_50 AC 88 ms
10,624 KB
testcase_51 AC 93 ms
10,752 KB
testcase_52 AC 89 ms
10,880 KB
testcase_53 AC 92 ms
10,624 KB
testcase_54 AC 92 ms
10,624 KB
testcase_55 AC 94 ms
10,624 KB
testcase_56 AC 92 ms
10,624 KB
testcase_57 AC 92 ms
10,624 KB
testcase_58 AC 93 ms
10,624 KB
testcase_59 AC 105 ms
10,880 KB
testcase_60 AC 106 ms
10,624 KB
testcase_61 AC 108 ms
10,624 KB
testcase_62 AC 106 ms
10,752 KB
testcase_63 AC 101 ms
10,624 KB
testcase_64 AC 105 ms
10,880 KB
testcase_65 AC 108 ms
10,752 KB
testcase_66 AC 103 ms
10,752 KB
testcase_67 AC 103 ms
10,624 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