結果
問題 | No.424 立体迷路 |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-11 21:00:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 81,940 KB |
実行使用メモリ | 67,840 KB |
最終ジャッジ日時 | 2024-07-18 08:39:29 |
合計ジャッジ時間 | 2,059 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
from collections import dequeH,W=map(int,input().split())sx,sy,tx,ty=map(int,input().split())sx-=1;sy-=1;tx-=1;ty-=1S=[]for _ in range(H):S.append(list(map(int,input())))M=[(1,0),(-1,0),(0,1),(0,-1)]T=[[0]*W for _ in range(H)]T[sx][sy]=1Q=deque([(sx,sy)])while Q:x,y=Q.popleft()#隣のマスに移動for a,b in M:if not (0<=x+a<H and 0<=y+b<W):continueif abs(S[x][y]-S[x+a][y+b])>=2:continueif T[x+a][y+b]==0:T[x+a][y+b]=1Q.append((x+a,y+b))#2個隣のマスに移動for a,b in M:if not(0<=x+2*a<H and 0<=y+2*b<W):continueif S[x][y]==S[x+2*a][y+2*b] and S[x][y]>S[x+a][y+b]:if T[x+2*a][y+2*b]==0:T[x+2*a][y+2*b]=1Q.append((x+2*a,y+2*b))print("YES" if T[tx][ty] else "NO")