結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-02 14:57:14 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,483 bytes |
| コンパイル時間 | 148 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2024-11-21 13:03:14 |
| 合計ジャッジ時間 | 2,167 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 18 WA * 3 |
ソースコード
import queue
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def bfs(sy, sx, gy, gx, field):
q = queue.Queue()
q.put((sy, sx))
used = [[False] * len(field[0]) for i in range(len(field))]
used[sy][sx] = True
while not q.empty():
now_y, now_x = q.get(0)
now_h = field[now_y][now_x]
if (now_y, now_x) == (gx, gy):
break
for i in range(len(dy)):
next_y, next_x = now_y + dy[i], now_x + dx[i]
if 0 <= next_y < len(field) and 0 <= next_x < len(field[0]) and not used[next_y][next_x]:
next_h = field[next_y][next_x]
if abs(now_h - next_h) <= 1:
q.put((next_y, next_x))
used[next_y][next_x] = True
for i in range(len(dy)):
next_y, next_x = now_y + dy[i] * 2, now_x + dx[i] * 2
if 0 <= next_y < len(field) and 0 <= next_x < len(field[0]) and not used[next_y][next_x]:
next_h = field[next_y][next_x]
if now_h == next_h:
q.put((next_y, next_x))
used[next_y][next_x] = True
return used[gy][gx]
def main():
h, w = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())
sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1
field = []
for _ in range(h):
field.append(list(map(int, input())))
print("YES" if bfs(sx, sy, gx, gy, field) else "NO")
if __name__ == '__main__':
main()