結果
問題 | No.424 立体迷路 |
ユーザー | ayaoni |
提出日時 | 2020-12-18 05:32:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,857 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 66,692 KB |
最終ジャッジ日時 | 2024-09-21 08:54:47 |
合計ジャッジ時間 | 2,528 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
import sys from collections import deque sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) H,W = MI() sx,sy,gx,gy = MI() B = [[0]*(W+1)]+[[0]+LI2() for _ in range(H)] flag = [[0]*(W+1) for _ in range(H+1)] flag[sx][sy] = 1 deq = deque([(sx,sy)]) while deq: x,y = deq.pop() if 1 <= x-1 <= H and flag[x-1][y] == 0 and abs(B[x-1][y]-B[x][y]) <= 1: flag[x-1][y] = 1 deq.appendleft((x-1,y)) if 1 <= x+1 <= H and flag[x+1][y] == 0 and abs(B[x+1][y]-B[x][y]) <= 1: flag[x+1][y] = 1 deq.appendleft((x+1,y)) if 1 <= y-1 <= W and flag[x][y-1] == 0 and abs(B[x][y-1]-B[x][y]) <= 1: flag[x][y-1] = 1 deq.appendleft((x,y-1)) if 1 <= y+1 <= W and flag[x][y+1] == 0 and abs(B[x][y+1]-B[x][y]) <= 1: flag[x][y+1] = 1 deq.appendleft((x,y+1)) if 1 <= x-2 <= H and flag[x-2][y] == 0 and B[x-2][y] == B[x][y] and B[x-1][y] < B[x][y]: flag[x-2][y] = 1 deq.appendleft((x-2,y)) if 1 <= x+2 <= H and flag[x+2][y] == 0 and B[x+2][y] == B[x][y] and B[x+1][y] < B[x][y]: flag[x+2][y] = 1 deq.appendleft((x+2,y)) if 1 <= y-2 <= W and flag[x][y-2] == 0 and B[x][y-2] == B[x][y] and B[x][y-1] < B[x][y]: flag[x][y-2] = 1 deq.appendleft((x,y-2)) if 1 <= y+2 <= W and flag[x][y+2] == 0 and B[x][y+2] == B[x][y] and B[x][y+1] < B[x][y]: flag[x][y+2] = 1 deq.appendleft((x,y+2)) if flag[gx][gy]: print('YES') else: print('NO')