結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2023-03-29 01:27:41 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,128 bytes |
コンパイル時間 | 76 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-09-20 13:26:17 |
合計ジャッジ時間 | 1,667 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from collections import deque H,W=map(int,input().split()) sx,sy,gx,gy=map(int,input().split()) MAP=[list(map(int,list(input().strip()))) for i in range(H)] USE=[[0]*W for i in range(H)] USE[sx-1][sy-1]=1 Q=deque([(sx-1,sy-1)]) while Q: x,y=Q.popleft() for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z<H and 0<=w<W and USE[z][w]==0: if abs(MAP[x][y]-MAP[z][w])<=1: USE[z][w]=1 Q.append((z,w)) if x-2>=0: if USE[x-2][y]==0 and MAP[x-2][y]==MAP[x][y] and MAP[x-1][y]<MAP[x][y]: USE[x-2][y]=1 Q.append((x-2,y)) if y-2>=0: if USE[x][y-2]==0 and MAP[x][y-2]==MAP[x][y] and MAP[x][y-1]<MAP[x][y]: USE[x][y-2]=1 Q.append((x,y-2)) if x+2<H: if USE[x+2][y]==0 and MAP[x+2][y]==MAP[x][y] and MAP[x+1][y]<MAP[x][y]: USE[x+2][y]=1 Q.append((x+2,y)) if y+2<W: if USE[x][y+2]==0 and MAP[x][y+2]==MAP[x][y] and MAP[x][y+1]<MAP[x][y]: USE[x][y+2]=1 Q.append((x,y+2)) if USE[gx-1][gy-1]==1: print("YES") else: print("NO")