結果

問題 No.621 3 x N グリッド上のドミノの置き方の数
ユーザー しらっ亭しらっ亭
提出日時 2017-12-08 02:53:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 164 ms / 3,000 ms
コード長 2,142 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 76,468 KB
最終ジャッジ日時 2024-11-29 05:44:31
合計ジャッジ時間 9,488 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
61,312 KB
testcase_01 AC 50 ms
65,168 KB
testcase_02 AC 43 ms
61,092 KB
testcase_03 AC 43 ms
62,216 KB
testcase_04 AC 46 ms
63,144 KB
testcase_05 AC 45 ms
63,352 KB
testcase_06 AC 45 ms
64,320 KB
testcase_07 AC 47 ms
63,084 KB
testcase_08 AC 48 ms
64,820 KB
testcase_09 AC 47 ms
63,492 KB
testcase_10 AC 48 ms
63,988 KB
testcase_11 AC 47 ms
64,420 KB
testcase_12 AC 53 ms
67,060 KB
testcase_13 AC 57 ms
68,244 KB
testcase_14 AC 67 ms
72,932 KB
testcase_15 AC 83 ms
75,928 KB
testcase_16 AC 82 ms
75,944 KB
testcase_17 AC 80 ms
75,952 KB
testcase_18 AC 89 ms
76,008 KB
testcase_19 AC 91 ms
76,124 KB
testcase_20 AC 97 ms
76,156 KB
testcase_21 AC 96 ms
76,124 KB
testcase_22 AC 108 ms
75,728 KB
testcase_23 AC 108 ms
75,992 KB
testcase_24 AC 122 ms
76,276 KB
testcase_25 AC 126 ms
75,832 KB
testcase_26 AC 125 ms
76,112 KB
testcase_27 AC 136 ms
76,152 KB
testcase_28 AC 134 ms
75,692 KB
testcase_29 AC 136 ms
75,964 KB
testcase_30 AC 132 ms
76,372 KB
testcase_31 AC 140 ms
76,012 KB
testcase_32 AC 129 ms
76,468 KB
testcase_33 AC 135 ms
76,288 KB
testcase_34 AC 136 ms
76,080 KB
testcase_35 AC 128 ms
75,696 KB
testcase_36 AC 131 ms
76,112 KB
testcase_37 AC 144 ms
76,008 KB
testcase_38 AC 145 ms
76,072 KB
testcase_39 AC 143 ms
75,896 KB
testcase_40 AC 148 ms
76,272 KB
testcase_41 AC 145 ms
76,028 KB
testcase_42 AC 142 ms
76,088 KB
testcase_43 AC 148 ms
76,048 KB
testcase_44 AC 154 ms
75,900 KB
testcase_45 AC 140 ms
76,212 KB
testcase_46 AC 143 ms
75,948 KB
testcase_47 AC 144 ms
75,896 KB
testcase_48 AC 143 ms
76,088 KB
testcase_49 AC 143 ms
75,820 KB
testcase_50 AC 144 ms
75,760 KB
testcase_51 AC 141 ms
75,896 KB
testcase_52 AC 142 ms
76,224 KB
testcase_53 AC 145 ms
76,120 KB
testcase_54 AC 149 ms
75,756 KB
testcase_55 AC 158 ms
76,304 KB
testcase_56 AC 157 ms
76,184 KB
testcase_57 AC 148 ms
75,816 KB
testcase_58 AC 133 ms
76,060 KB
testcase_59 AC 160 ms
76,012 KB
testcase_60 AC 159 ms
76,084 KB
testcase_61 AC 159 ms
75,800 KB
testcase_62 AC 164 ms
76,240 KB
testcase_63 AC 106 ms
75,828 KB
testcase_64 AC 107 ms
76,192 KB
testcase_65 AC 114 ms
75,840 KB
testcase_66 AC 112 ms
75,860 KB
testcase_67 AC 108 ms
75,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7

range64 = range(64)

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


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

	for i in range64:
		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 range64]

	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