結果

問題 No.424 立体迷路
ユーザー pluto77
提出日時 2018-01-27 11:03:05
言語 Python2
(2.7.18)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2024-07-05 07:15:09
合計ジャッジ時間 1,253 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#yuki424
import Queue
h,w = map(int, raw_input().split())
sx,sy,gx,gy = map(int, raw_input().split())
sx,sy,gx,gy=sx-1,sy-1,gx-1,gy-1
l=[]
for i in xrange(h):
l.append(map(int,list(raw_input())))
ls = [[True for i in range(w)] for j in range(h)]
q = Queue.Queue()
q.put((sx,sy))
ls[sx][sy] = False
f = False
while not q.empty():
x,y = q.get()
if x == gx and y == gy:
f = True
break;
for dx,dy in [(-1,0),(1,0),(0,-1),(0,1)]:
if 0 <= x+dx and x+dx < h and 0 <= y+dy and y+dy < w and ls[x+dx][y+dy] and abs(l[x][y] - l[x+dx][y+dy]) < 2:
q.put((x+dx,y+dy))
ls[x+dx][y+dy] = False
for dx,dy in [(-2,0),(2,0),(0,-2),(0,2)]:
if 0 <= x+dx and x+dx < h and 0 <= y+dy and y+dy < w and ls[x+dx][y+dy] and l[x][y] == l[x+dx][y+dy] and l[x+dx/2][y+dy/2] < l[x][y]:
q.put((x+dx,y+dy))
ls[x+dx][y+dy] = False
if f:
print 'YES'
else:
print 'NO'
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0