結果

問題 No.2928 Gridpath
ユーザー hiro1729
提出日時 2024-10-12 15:18:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-10-12 15:18:34
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
Si, Sj = map(int, input().split())
Gi, Gj = map(int, input().split())
Si -= 1
Sj -= 1
Gi -= 1
Gj -= 1

def dfs(c, x, y):
	if x == Gi and y == Gj:
		return 1
	ans = 0
	for nx, ny in [(x - 1, y), (x, y - 1), (x + 1, y), (x, y + 1)]:
		if 0 <= nx < H and 0 <= ny < W and c & (1 << (nx * W + ny)) == 0:
			cn = 0
			for nnx, nny in [(nx - 1, ny), (nx, ny - 1), (nx + 1, ny), (nx, ny + 1)]:
				if 0 <= nnx < H and 0 <= nny < W and c & (1 << (nnx * W + nny)):
					cn += 1
			if cn == 1:
				ans += dfs(c | (1 << (nx * W + ny)), nx, ny)
	return ans

print(dfs(1 << (Si * W + Sj), Si, Sj))
0