結果
問題 | No.1638 Robot Maze |
ユーザー |
👑 |
提出日時 | 2022-01-26 16:05:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 869 bytes |
コンパイル時間 | 557 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 77,260 KB |
最終ジャッジ日時 | 2024-12-23 06:53:14 |
合計ジャッジ時間 | 6,830 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
from heapq import *h, w = map(int, input().split())u, d, r, l, k, p = map(int, input().split())xs, ys, xt, yt = map(int, input().split())C = [input() for _ in range(h)]xs -= 1ys -= 1xt -= 1yt -= 1directions = [(-1, 0, u), (1, 0, d), (0, 1, r), (0, -1, l)]inf = 1 << 60dist = [[inf] * w for _ in range(h)]hq = [(0, xs, ys)]dist[xs][ys] = 0while hq:d, x, y = heappop(hq)if d > dist[x][y]:continuefor dx, dy, dd in directions:nx = x + dxny = y + dynd = d + ddif nx == -1 or ny == -1 or nx == h or ny == w:continueif C[nx][ny] == "#":continueif C[nx][ny] == "@":nd += pif dist[nx][ny] > nd:dist[nx][ny] = ndheappush(hq, (nd, nx, ny))if dist[xt][yt] <= k:print("Yes")else:print("No")