結果
問題 |
No.424 立体迷路
|
ユーザー |
![]() |
提出日時 | 2024-01-03 16:15:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 57 ms / 2,000 ms |
コード長 | 921 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,060 KB |
実行使用メモリ | 68,800 KB |
最終ジャッジ日時 | 2024-09-27 18:27:11 |
合計ジャッジ時間 | 1,988 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
H,W = map(int,input().split()) SG = [i-1 for i in list(map(int,input().split()))] S = tuple(SG[:2]) G = tuple(SG[2:]) B = [[int(s) for s in input()] for _ in range(H)] Q = {S} dir = [[1,0],[0,1],[-1,0],[0,-1]] nv = [[True] * W for _ in range(H)] nv[S[0]][S[1]] = False while Q: x,y = next(iter(Q)) if G == (x,y): print("YES") exit() Q.remove((x,y)) nowh = B[x][y] for xd,yd in dir: x2 = x + xd y2 = y + yd if 0 <= x2 < H and 0 <= y2 < W: if nv[x2][y2] and abs(B[x2][y2] - nowh) <= 1: nv[x2][y2] = False Q.add((x2,y2)) for xd,yd in dir: x2 = x + xd * 2 y2 = y + yd * 2 x3 = x + xd y3 = y + yd if 0 <= x2 < H and 0 <= y2 < W: if nv[x2][y2] and B[x2][y2] == nowh and B[x3][y3] < nowh: nv[x2][y2] = False Q.add((x2,y2)) print("NO")