結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー しらっ亭
提出日時 2017-12-08 02:22:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 2,055 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 29,348 KB
最終ジャッジ日時 2024-11-29 05:41:56
合計ジャッジ時間 195,871 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 TLE * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7


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


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

	for i in range(64):
		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):
	mat = [[0] * 64 for _ in range(64)]

	b3 = 8

	for i in range(b3):
		i0 = (i & 1) != 0
		i1 = (i & 2) != 0
		i2 = (i & 4) != 0
		for j in range(b3):
			j0 = (j & 1) != 0
			j1 = (j & 2) != 0
			j2 = (j & 4) != 0

			fr = (j << 3) | i

			for p0 in range(2):
				if i0 and p0:
					continue
				if not j0 and not p0:
					continue
				for p1 in range(2):
					if i1 and p1:
						continue
					if not j1 and not p1:
						continue
					for p2 in range(2):
						if i2 and p2:
							continue
						if not j2 and not p2:
							continue

						if (i0 | p0) == 0 and (i1 | p1) == 0:
							continue
						if (i2 | p2) == 0 and (i1 | p1) == 0:
							continue

						y = (p2 << 2) + (p1 << 1) + p0
						x = y | i
						to = (x << 3) | y
						mat[fr][to] += 1

			if not i0 and not i1:
				if i2:
					x = 3 + (1 << 2)
					y = 0 + (0 << 2)
					to = (x << 3) | y
					mat[fr][to] += 1
				elif j2:
					for p2 in range(2):
						x = 3 + (p2 << 2)
						y = 0 + (p2 << 2)
						to = (x << 3) | y
						mat[fr][to] += 1
				else:
					x = 3 + (1 << 2)
					y = 0 + (1 << 2)
					to = (x << 3) | y
					mat[fr][to] += 1

			if not i1 and not i2:
				if i0:
					x = 6 + (1 << 0)
					y = 0 + (0 << 0)
					to = (x << 3) | y
					mat[fr][to] += 1
				elif j0:
					for p2 in range(2):
						x = 6 + (p2 << 0)
						y = 0 + (p2 << 0)
						to = (x << 3) | y
						mat[fr][to] += 1
				else:
					x = 6 + (1 << 0)
					y = 0 + (1 << 0)
					to = (x << 3) | y
					mat[fr][to] += 1

	mat = mat_pow(mat, n)

	ans = 0
	for j in range(2, b3):
		if j == 4:
			continue
		fr = j << 3
		ans += mat[0b111000][fr]

	return ans % mod
	

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