結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー しらっ亭しらっ亭
提出日時 2017-12-08 02:22:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,055 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-05-06 19:48:34
合計ジャッジ時間 40,123 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
22,528 KB
testcase_01 AC 345 ms
11,264 KB
testcase_02 AC 116 ms
11,136 KB
testcase_03 AC 157 ms
11,264 KB
testcase_04 AC 199 ms
11,264 KB
testcase_05 AC 201 ms
11,392 KB
testcase_06 AC 243 ms
11,264 KB
testcase_07 AC 242 ms
11,136 KB
testcase_08 AC 282 ms
11,136 KB
testcase_09 AC 251 ms
11,264 KB
testcase_10 AC 290 ms
11,264 KB
testcase_11 AC 301 ms
11,264 KB
testcase_12 AC 522 ms
11,264 KB
testcase_13 AC 632 ms
11,392 KB
testcase_14 AC 943 ms
11,136 KB
testcase_15 AC 1,261 ms
11,264 KB
testcase_16 AC 1,456 ms
11,264 KB
testcase_17 AC 1,525 ms
11,264 KB
testcase_18 AC 1,958 ms
11,136 KB
testcase_19 AC 2,027 ms
11,136 KB
testcase_20 AC 2,296 ms
11,392 KB
testcase_21 AC 2,381 ms
11,264 KB
testcase_22 AC 2,834 ms
11,264 KB
testcase_23 AC 2,915 ms
11,392 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
権限があれば一括ダウンロードができます

ソースコード

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