結果

問題 No.1638 Robot Maze
ユーザー wolgnikwolgnik
提出日時 2021-08-06 21:48:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 1,240 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 80,208 KB
最終ジャッジ日時 2024-04-25 22:22:29
合計ジャッジ時間 7,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,744 KB
testcase_01 AC 41 ms
53,548 KB
testcase_02 AC 40 ms
53,916 KB
testcase_03 AC 108 ms
79,896 KB
testcase_04 AC 43 ms
54,836 KB
testcase_05 AC 43 ms
54,896 KB
testcase_06 AC 43 ms
54,464 KB
testcase_07 AC 42 ms
54,088 KB
testcase_08 AC 43 ms
54,236 KB
testcase_09 AC 43 ms
55,104 KB
testcase_10 AC 42 ms
54,820 KB
testcase_11 AC 43 ms
55,332 KB
testcase_12 AC 43 ms
55,536 KB
testcase_13 AC 43 ms
55,132 KB
testcase_14 AC 127 ms
79,084 KB
testcase_15 AC 104 ms
78,304 KB
testcase_16 AC 113 ms
78,152 KB
testcase_17 AC 113 ms
78,264 KB
testcase_18 AC 65 ms
68,952 KB
testcase_19 AC 110 ms
78,016 KB
testcase_20 AC 112 ms
78,108 KB
testcase_21 AC 71 ms
73,756 KB
testcase_22 AC 71 ms
73,312 KB
testcase_23 AC 74 ms
73,196 KB
testcase_24 AC 74 ms
73,176 KB
testcase_25 AC 72 ms
72,932 KB
testcase_26 AC 82 ms
77,980 KB
testcase_27 AC 81 ms
77,772 KB
testcase_28 AC 83 ms
77,916 KB
testcase_29 AC 82 ms
78,096 KB
testcase_30 AC 42 ms
53,796 KB
testcase_31 AC 41 ms
53,856 KB
testcase_32 AC 145 ms
79,668 KB
testcase_33 AC 143 ms
79,552 KB
testcase_34 AC 134 ms
80,096 KB
testcase_35 AC 152 ms
79,836 KB
testcase_36 AC 140 ms
79,788 KB
testcase_37 AC 137 ms
79,620 KB
testcase_38 AC 150 ms
79,812 KB
testcase_39 AC 139 ms
79,800 KB
testcase_40 AC 132 ms
79,528 KB
testcase_41 AC 156 ms
79,932 KB
testcase_42 AC 146 ms
79,816 KB
testcase_43 AC 174 ms
79,832 KB
testcase_44 AC 145 ms
79,728 KB
testcase_45 AC 158 ms
79,808 KB
testcase_46 AC 136 ms
79,840 KB
testcase_47 AC 134 ms
79,460 KB
testcase_48 AC 133 ms
80,080 KB
testcase_49 AC 144 ms
79,756 KB
testcase_50 AC 147 ms
80,120 KB
testcase_51 AC 146 ms
80,208 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