結果

問題 No.1638 Robot Maze
ユーザー qibqib
提出日時 2022-12-07 19:45:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 79,228 KB
最終ジャッジ日時 2024-04-22 01:43:14
合計ジャッジ時間 6,061 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,980 KB
testcase_01 AC 35 ms
53,980 KB
testcase_02 AC 33 ms
53,792 KB
testcase_03 AC 83 ms
77,440 KB
testcase_04 AC 34 ms
53,168 KB
testcase_05 AC 34 ms
53,544 KB
testcase_06 AC 34 ms
53,604 KB
testcase_07 AC 38 ms
53,760 KB
testcase_08 AC 40 ms
54,056 KB
testcase_09 AC 37 ms
53,744 KB
testcase_10 AC 39 ms
53,928 KB
testcase_11 AC 37 ms
53,356 KB
testcase_12 AC 34 ms
53,744 KB
testcase_13 AC 35 ms
54,492 KB
testcase_14 AC 84 ms
77,496 KB
testcase_15 AC 92 ms
78,020 KB
testcase_16 AC 91 ms
78,024 KB
testcase_17 AC 98 ms
78,136 KB
testcase_18 AC 43 ms
67,960 KB
testcase_19 AC 78 ms
77,372 KB
testcase_20 AC 77 ms
77,648 KB
testcase_21 AC 55 ms
73,584 KB
testcase_22 AC 55 ms
73,536 KB
testcase_23 AC 53 ms
73,428 KB
testcase_24 AC 55 ms
73,872 KB
testcase_25 AC 63 ms
73,664 KB
testcase_26 AC 78 ms
77,672 KB
testcase_27 AC 78 ms
77,888 KB
testcase_28 AC 86 ms
77,664 KB
testcase_29 AC 83 ms
77,776 KB
testcase_30 AC 37 ms
53,096 KB
testcase_31 AC 38 ms
53,388 KB
testcase_32 AC 101 ms
77,444 KB
testcase_33 AC 132 ms
78,740 KB
testcase_34 AC 101 ms
77,948 KB
testcase_35 AC 151 ms
78,880 KB
testcase_36 AC 117 ms
78,428 KB
testcase_37 AC 93 ms
77,396 KB
testcase_38 AC 99 ms
77,440 KB
testcase_39 AC 103 ms
78,012 KB
testcase_40 AC 157 ms
79,228 KB
testcase_41 AC 113 ms
78,440 KB
testcase_42 AC 122 ms
78,320 KB
testcase_43 AC 121 ms
78,164 KB
testcase_44 AC 122 ms
78,016 KB
testcase_45 AC 126 ms
78,604 KB
testcase_46 AC 107 ms
78,096 KB
testcase_47 AC 95 ms
77,484 KB
testcase_48 AC 115 ms
78,260 KB
testcase_49 AC 110 ms
78,236 KB
testcase_50 AC 117 ms
78,140 KB
testcase_51 AC 118 ms
78,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

INF = 1 << 60

h, w = map(int, input().split())
u, d, r, l, k, p = map(int, input().split())
xs, ys, xt, yt = map(int, input().split())
xs -= 1
ys -= 1
xt -= 1
yt -= 1

c = [input() for _ in range(h)]
dist = [[[INF for _ in range(2)] for _ in range(w)] for _ in range(h)]
dist[xs][ys][0] = 0

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
cost = [[d, d + p], [r, r + p], [u, u + p], [l, l + p]]

hp = [(0, xs, ys, 0)]
while len(hp) > 0:
  cd, cx, cy, ci = heapq.heappop(hp)
  if dist[cx][cy][ci] < cd:
    continue
  for d in range(4):
    nx = cx + dx[d]
    if nx < 0 or nx >= h:
      continue
    ny = cy + dy[d]
    if ny < 0 or ny >= w:
      continue
    if c[nx][ny] == '#':
      continue
    ni = 1 if c[nx][ny] == '@' else 0

    if dist[nx][ny][ni] > dist[cx][cy][ci] + cost[d][ni]:
      dist[nx][ny][ni] = dist[cx][cy][ci] + cost[d][ni]
      heapq.heappush(hp, (dist[nx][ny][ni], nx, ny, ni))

ans = "Yes" if dist[xt][yt][0] <= k else "No"
print(ans)
0