結果
| 問題 |
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 -= 1
ys -= 1
xt -= 1
yt -= 1
directions = [(-1, 0, u), (1, 0, d), (0, 1, r), (0, -1, l)]
inf = 1 << 60
dist = [[inf] * w for _ in range(h)]
hq = [(0, xs, ys)]
dist[xs][ys] = 0
while hq:
d, x, y = heappop(hq)
if d > dist[x][y]:
continue
for dx, dy, dd in directions:
nx = x + dx
ny = y + dy
nd = d + dd
if nx == -1 or ny == -1 or nx == h or ny == w:
continue
if C[nx][ny] == "#":
continue
if C[nx][ny] == "@":
nd += p
if dist[nx][ny] > nd:
dist[nx][ny] = nd
heappush(hq, (nd, nx, ny))
if dist[xt][yt] <= k:
print("Yes")
else:
print("No")