結果
| 問題 | 
                            No.424 立体迷路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yn
                         | 
                    
| 提出日時 | 2016-10-25 23:56:01 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 61 ms / 2,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 134 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 67,968 KB | 
| 最終ジャッジ日時 | 2024-07-05 07:11:33 | 
| 合計ジャッジ時間 | 1,765 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 21 | 
ソースコード
h, w = map(int,input().split())
sx, sy, gx, gy = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
b = [list(input()) for j in range(h)]
dx = [ 1, 0,-1, 0]
dy = [ 0, 1, 0,-1]
ddx = [2, 0,-2, 0]
ddy = [0, 2, 0,-2]
visited = [[False] * w for j in range(h)]
visited[sx][sy] = True
qx = []
qy = []
qx.append(sx)
qy.append(sy)
while len(qx) != 0:
    curx = qx.pop(0)
    cury = qy.pop(0)
    cur = int(b[curx][cury])
    for i in range(4):
        nextx = curx + dx[i]
        nexty = cury + dy[i]
        if 0 <= nextx < h and 0 <= nexty < w:
            pass
        else:
            continue
        if abs(cur - int(b[nextx][nexty])) <= 1:
            if not visited[nextx][nexty]:
                visited[nextx][nexty] = True
                qx.append(nextx)
                qy.append(nexty)
    for i in range(4):
        nextx = curx + ddx[i]
        nexty = cury + ddy[i]
        if 0 <= nextx < h and 0 <= nexty < w:
            pass
        else:
            continue
        if cur != int(b[nextx][nexty]):
            continue
        valleyx = curx + dx[i]
        valleyy = cury + dy[i]
        if int(b[valleyx][valleyy]) < cur:
            if not visited[nextx][nexty]:
                visited[nextx][nexty] = True
                qx.append(nextx)
                qy.append(nexty)
if visited[gx][gy]:
    print("YES")
else:
    print("NO")
            
            
            
        
            
yn