結果
問題 |
No.424 立体迷路
|
ユーザー |
|
提出日時 | 2020-12-19 17:05:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 1,043 bytes |
コンパイル時間 | 264 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 67,712 KB |
最終ジャッジ日時 | 2024-09-21 10:26:58 |
合計ジャッジ時間 | 2,367 ms |
ジャッジサーバーID (参考情報) |
judge3 / 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()) sx -= 1 sy -= 1 gx -= 1 gy -= 1 B = [list(str(input())) for _ in range(H)] visited = [[0 for _ in range(W)] for _ in range(H)] visited[sx][sy] = 1 que = deque([(sx,sy,int(B[sx][sy]))]) move = [(-1,0),(0,-1),(1,0),(0,1)] while que: x,y,z = que.pop() if x == gx and y == gy: print("YES") exit() for i,j in move: h,w = x+i,y+j if 0 <= h < H and 0 <= w < W: if visited[h][w] == 0: if int(B[h][w])-1 <= z <= int(B[h][w])+1: visited[h][w] = 1 que.append((h,w,int(B[h][w]))) if z > int(B[h][w]): h += i w += j if 0 <= h < H and 0 <= w < W: if visited[h][w] == 0: if z == int(B[h][w]): visited[h][w] = 1 que.append((h,w,int(B[h][w]))) print("NO")