結果

問題 No.1638 Robot Maze
ユーザー wolgnik
提出日時 2021-08-06 21:48:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-11-08 10:28:31
合計ジャッジ時間 7,850 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
sy, sx, gy, gx = map(lambda x: int(x) - 1, input().split())
a = [list(input())[: -1] for _ in range(H)]

e = [[] for _ in range(H * W)]
d = [-1, 0, 1, 0]
dc = [U, R, D, L]
for i in range(H):
  for j in range(W):
    if a[i][j] == "#": continue
    for k in range(4):
      u = i + d[k]
      v = j + d[~k]
      if u in range(H) and v in range(W):
        if a[u][v] == ".": e[i * W + j].append((u * W + v, dc[k]))
        if a[u][v] == "@": e[i * W + j].append((u * W + v, dc[k] + P))

import heapq
hpush = heapq.heappush
hpop = heapq.heappop
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s):
    d = [float("inf")] * (self.n + 1)
    vis = [0] * (self.n + 1)
    d[s] = 0
    h = [s]
    while len(h):
      v = hpop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if vis[v1]: continue
      vis[v1] = 1
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if vis[p[0]]: continue
        hpush(h, d[p[0]] * (10 ** 6) + p[0])
    return d

dij = dijkstra(H * W, e)
if dij.path(sy * W + sx)[gy * W + gx] <= K: print("Yes")
else: print("No")
0