結果

問題 No.424 立体迷路
ユーザー niodachi1niodachi1
提出日時 2019-10-16 10:37:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 910 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 11,044 KB
実行使用メモリ 10,660 KB
最終ジャッジ日時 2023-09-02 11:09:31
合計ジャッジ時間 1,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,084 KB
testcase_01 AC 15 ms
8,108 KB
testcase_02 AC 16 ms
8,040 KB
testcase_03 AC 16 ms
8,116 KB
testcase_04 AC 17 ms
8,420 KB
testcase_05 AC 15 ms
8,144 KB
testcase_06 AC 16 ms
8,140 KB
testcase_07 AC 16 ms
8,084 KB
testcase_08 AC 16 ms
8,068 KB
testcase_09 AC 16 ms
8,084 KB
testcase_10 AC 16 ms
8,072 KB
testcase_11 AC 15 ms
8,144 KB
testcase_12 AC 16 ms
8,072 KB
testcase_13 AC 15 ms
8,212 KB
testcase_14 AC 15 ms
8,120 KB
testcase_15 AC 16 ms
8,076 KB
testcase_16 AC 16 ms
8,228 KB
testcase_17 AC 16 ms
8,368 KB
testcase_18 AC 16 ms
8,448 KB
testcase_19 AC 17 ms
8,332 KB
testcase_20 AC 16 ms
8,240 KB
testcase_21 AC 16 ms
8,240 KB
testcase_22 AC 17 ms
8,000 KB
testcase_23 AC 16 ms
8,080 KB
testcase_24 AC 29 ms
10,636 KB
testcase_25 AC 30 ms
10,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

h, w = map(int, input().split())
s_x, s_y, g_x, g_y = map(int, input().split())
s = [s_x-1, s_y-1]
g = [g_x-1, g_y-1]
b = [list(map(int, input())) for _ in range(h)]
flg = [[False for _ in range(w)] for _ in range(h)]

def judge(cx,cy,nx,ny):
	ch = b[cx][cy]
	nh = b[nx][ny]

	if abs(cx+cy-nx-ny) == 1:
		if abs(ch-nh) <= 1:
			return True

	elif abs(cx+cy-nx-ny) == 2:
		mh = b[(cx+nx)//2][(cy+ny)//2]
		if mh < ch and mh < nh and ch == nh:
			return True

def bfs(q):
	cx,cy = q.pop(0)

	next = [[cx+1, cy],[cx-1, cy],[cx, cy+1],[cx, cy-1],[cx+2, cy],[cx-2, cy],[cx, cy+2],[cx, cy-2]]
	for nx, ny in next:
		if 0 <= nx < h and 0 <= ny < w and flg[nx][ny] == False:
			if judge(cx, cy, nx, ny):
				flg[nx][ny] = True
				q.append([nx, ny])

	if len(q) == 0:
		return flg[g[0]][g[1]]

	return bfs(q)

q = []
q.append(s)

if bfs(q):
	print("YES")
else:
	print("NO")



0