結果

問題 No.1638 Robot Maze
ユーザー wolgnikwolgnik
提出日時 2021-08-06 21:48:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 82,024 KB
最終ジャッジ日時 2023-08-08 04:41:19
合計ジャッジ時間 10,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,132 KB
testcase_01 AC 75 ms
71,348 KB
testcase_02 AC 75 ms
71,452 KB
testcase_03 AC 138 ms
80,372 KB
testcase_04 AC 78 ms
71,136 KB
testcase_05 AC 78 ms
70,988 KB
testcase_06 AC 78 ms
71,244 KB
testcase_07 AC 77 ms
71,320 KB
testcase_08 AC 78 ms
71,160 KB
testcase_09 AC 76 ms
71,328 KB
testcase_10 AC 77 ms
71,348 KB
testcase_11 AC 77 ms
71,468 KB
testcase_12 AC 77 ms
71,400 KB
testcase_13 AC 77 ms
71,508 KB
testcase_14 AC 151 ms
80,508 KB
testcase_15 AC 133 ms
79,600 KB
testcase_16 AC 133 ms
79,652 KB
testcase_17 AC 131 ms
79,336 KB
testcase_18 AC 94 ms
76,708 KB
testcase_19 AC 129 ms
79,152 KB
testcase_20 AC 130 ms
79,416 KB
testcase_21 AC 107 ms
79,312 KB
testcase_22 AC 109 ms
79,008 KB
testcase_23 AC 107 ms
78,920 KB
testcase_24 AC 108 ms
79,188 KB
testcase_25 AC 105 ms
79,164 KB
testcase_26 AC 112 ms
79,528 KB
testcase_27 AC 110 ms
79,616 KB
testcase_28 AC 110 ms
79,408 KB
testcase_29 AC 109 ms
79,636 KB
testcase_30 AC 75 ms
71,244 KB
testcase_31 AC 75 ms
71,608 KB
testcase_32 AC 175 ms
81,424 KB
testcase_33 AC 173 ms
80,652 KB
testcase_34 AC 162 ms
80,824 KB
testcase_35 AC 183 ms
81,660 KB
testcase_36 AC 173 ms
80,716 KB
testcase_37 AC 163 ms
80,476 KB
testcase_38 AC 178 ms
80,308 KB
testcase_39 AC 170 ms
80,956 KB
testcase_40 AC 160 ms
80,944 KB
testcase_41 AC 186 ms
82,024 KB
testcase_42 AC 174 ms
80,992 KB
testcase_43 AC 206 ms
81,148 KB
testcase_44 AC 172 ms
80,700 KB
testcase_45 AC 191 ms
81,320 KB
testcase_46 AC 168 ms
80,608 KB
testcase_47 AC 158 ms
80,500 KB
testcase_48 AC 163 ms
80,576 KB
testcase_49 AC 174 ms
80,396 KB
testcase_50 AC 178 ms
81,440 KB
testcase_51 AC 174 ms
81,384 KB
権限があれば一括ダウンロードができます

ソースコード

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