結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
AEn
|
| 提出日時 | 2022-06-18 01:08:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 165 ms / 2,000 ms |
| コード長 | 1,441 bytes |
| コンパイル時間 | 393 ms |
| コンパイル使用メモリ | 82,440 KB |
| 実行使用メモリ | 79,628 KB |
| 最終ジャッジ日時 | 2024-10-09 11:41:03 |
| 合計ジャッジ時間 | 6,906 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
from heapq import heappush, heappop
INF = float('inf')
x = [1, 0, 0, -1]
y = [0, 1, -1, 0]
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
cost = [D, R, L, U]
sx, sy, gx, gy = map(int, input().split())
sx-=1;sy-=1;gx-=1;gy-=1
C = [list(input()) for _ in range(H)]
adj = [list() for _ in range(H*W)]
for i in range(H):
for j in range(W):
if C[i][j] == '#':
continue
else:
for cc, xx, yy in zip(cost, x, y):
cx, cy = i+xx, j+yy
if 0<=cx<H and 0<=cy<W:
if C[cx][cy] == '#':
continue
elif C[cx][cy] == '.':
adj[i*H+j].append((cx*H+cy, cc))
else:
adj[i*H+j].append((cx*H+cy, P+cc))
def dijkstra(s, n):
dist = [INF] * n
hq = [(0, s)] # (distance, node)
dist[s] = 0
seen = [False] * n # ノードが確定済みかどうか
# 経路復元用
# prev = [-1]*n
while hq:
dis, v = heappop(hq)
if dist[v] < dis:
continue
seen[v] = True
for to, cost in adj[v]:
if seen[to] == False and dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
# prev[to] = v
heappush(hq, (dist[to], to))
return dist
d = dijkstra(sx*H+sy, H*W)
if d[gx*H+gy]<=K:
print('Yes')
else:
print('No')
AEn