結果

問題 No.424 立体迷路
ユーザー niodachi1niodachi1
提出日時 2019-10-16 10:28:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 10,644 KB
最終ジャッジ日時 2023-09-02 10:53:38
合計ジャッジ時間 2,076 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,148 KB
testcase_01 AC 16 ms
8,076 KB
testcase_02 AC 16 ms
7,996 KB
testcase_03 AC 16 ms
8,076 KB
testcase_04 AC 17 ms
8,460 KB
testcase_05 AC 16 ms
8,024 KB
testcase_06 AC 16 ms
8,060 KB
testcase_07 AC 16 ms
8,064 KB
testcase_08 AC 16 ms
7,996 KB
testcase_09 AC 15 ms
8,068 KB
testcase_10 AC 16 ms
8,128 KB
testcase_11 WA -
testcase_12 AC 16 ms
8,136 KB
testcase_13 WA -
testcase_14 AC 17 ms
8,304 KB
testcase_15 WA -
testcase_16 AC 16 ms
8,088 KB
testcase_17 AC 27 ms
10,316 KB
testcase_18 AC 17 ms
8,288 KB
testcase_19 AC 28 ms
10,316 KB
testcase_20 AC 17 ms
8,288 KB
testcase_21 AC 15 ms
8,088 KB
testcase_22 WA -
testcase_23 AC 16 ms
8,076 KB
testcase_24 AC 30 ms
10,644 KB
testcase_25 AC 29 ms
10,604 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:
			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