結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-02-21 23:04:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 136 ms / 2,000 ms |
| コード長 | 1,713 bytes |
| コンパイル時間 | 153 ms |
| コンパイル使用メモリ | 82,428 KB |
| 実行使用メモリ | 79,856 KB |
| 最終ジャッジ日時 | 2024-07-22 06:59:58 |
| 合計ジャッジ時間 | 5,942 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
from heapq import heappush, heappop
inf = float('inf')
def dijkstra(s, g, N):
# ゴールがない場合はg=-1とする。
def cost(v, m):
return v * N + m
dist = [inf] * N
mindist = [inf] * N
seen = [False] * N
Q = [cost(0, s)]
while Q:
c, m = divmod(heappop(Q), N)
if seen[m]:
continue
seen[m] = True
dist[m] = c
if m == g:
return dist
#------heapをアップデートする。--------
for u, C in G[m]:
if seen[u]:
continue
newdist = dist[m] + C
#------------------------------------
if newdist >= mindist[u]:
continue
mindist[u] = newdist
heappush(Q, cost(newdist, u))
return dist
def f(h, w):
return h * W + w
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
cost = [D, R, U, L]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
sx, sy, gx, gy = map(int, input().split())
sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1
C = []
for i in range(H):
C.append(list(input()))
N = H * W
G = [[] for i in range(N)]
for h in range(H):
for w in range(W):
if C[h][w] == "#":
continue
for k in range(4):
x = h + dx[k]
y = w + dy[k]
if x < 0 or x > H - 1 or y < 0 or y > W - 1:
continue
if C[x][y] == "#":
continue
c = cost[k]
if C[x][y] == "@":
c += P
G[f(h,w)].append((f(x,y), c))
D = dijkstra(f(sx, sy), f(gx, gy), N)
if D[f(gx, gy)] <= K:
print("Yes")
else:
print("No")
rlangevin