結果

問題 No.424 立体迷路
ユーザー tookunn_1213tookunn_1213
提出日時 2016-09-22 23:07:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 8,188 KB
最終ジャッジ日時 2023-09-18 16:50:23
合計ジャッジ時間 1,596 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,188 KB
testcase_01 AC 16 ms
8,168 KB
testcase_02 AC 16 ms
8,008 KB
testcase_03 AC 16 ms
8,088 KB
testcase_04 AC 18 ms
8,032 KB
testcase_05 AC 17 ms
8,124 KB
testcase_06 AC 16 ms
8,156 KB
testcase_07 AC 16 ms
8,000 KB
testcase_08 AC 16 ms
8,044 KB
testcase_09 AC 16 ms
8,048 KB
testcase_10 AC 16 ms
8,036 KB
testcase_11 AC 16 ms
7,984 KB
testcase_12 AC 16 ms
8,000 KB
testcase_13 AC 16 ms
8,080 KB
testcase_14 AC 16 ms
8,140 KB
testcase_15 AC 16 ms
8,136 KB
testcase_16 AC 16 ms
8,040 KB
testcase_17 AC 17 ms
8,040 KB
testcase_18 AC 16 ms
8,044 KB
testcase_19 AC 16 ms
8,144 KB
testcase_20 AC 16 ms
7,992 KB
testcase_21 AC 16 ms
8,004 KB
testcase_22 AC 17 ms
8,004 KB
testcase_23 AC 16 ms
8,000 KB
testcase_24 AC 53 ms
8,000 KB
testcase_25 AC 53 ms
8,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W = map(int,input().split())
sy,sx,gy,gx = map(int,input().split())
sx,sy,gx,gy = sx - 1,sy-1,gx-1,gy-1
b = [input() for i in range(H)]
used = [[False for j in range(W)]for i in range(H)]
dx = [0,0,-1,1]
dy = [1,-1,0,0]
q = [(sy,sx)]
flag = False
while len(q) > 0:
	d = q.pop(0)
	if used[d[0]][d[1]]:
		continue
	used[d[0]][d[1]] = True
	if d[0] == gy and d[1] == gx:
		print('YES')
		flag = True
		break
	for i in range(4):
		nx = dx[i] + d[1]
		ny = dy[i] + d[0]
		if nx < 0 or ny < 0 or nx >= W or ny >= H:
			continue
		if b[ny][nx] == b[d[0]][d[1]]:
			q.append([ny,nx])
		if abs(int(b[ny][nx]) - int(b[d[0]][d[1]])) == 1:
			q.append([ny,nx])
	for i in range(4):
		nx = dx[i] + d[1]
		ny = dy[i] + d[0]
		nnx = dx[i] * 2 + d[1]
		nny = dy[i] * 2 + d[0]
		if nnx < 0 or nny < 0 or nnx >= W or nny >= H:
			continue
		if nx < 0 or ny < 0 or nx >= W or ny >= H:
			continue
		if b[nny][nnx] == b[d[0]][d[1]] and int(b[nny][nnx]) > int(b[ny][nx]):
			q.append([nny,nnx])
if not flag:
	print('NO')
0