結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:33:31 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 103 ms / 2,000 ms |
| コード長 | 1,325 bytes |
| コンパイル時間 | 136 ms |
| コンパイル使用メモリ | 82,820 KB |
| 実行使用メモリ | 77,684 KB |
| 最終ジャッジ日時 | 2025-03-31 17:34:04 |
| 合計ジャッジ時間 | 4,691 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
import heapq
h, w = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
x_s, y_s, x_t, y_t = map(int, input().split())
# Convert to 0-based indices
x_s -= 1
y_s -= 1
x_t -= 1
y_t -= 1
grid = []
for _ in range(h):
grid.append(list(input().strip()))
# Directions: up, down, right, left
dirs = [ (-1, 0, U), (1, 0, D), (0, 1, R), (0, -1, L) ]
INF = float('inf')
distance = [[INF for _ in range(w)] for __ in range(h)]
distance[x_s][y_s] = 0
heap = []
heapq.heappush(heap, (0, x_s, y_s))
found = False
while heap:
cost, i, j = heapq.heappop(heap)
if i == x_t and j == y_t:
if cost <= K:
print("Yes")
found = True
break
continue
if cost > distance[i][j]:
continue
for dx, dy, dir_cost in dirs:
ni = i + dx
nj = j + dy
if 0 <= ni < h and 0 <= nj < w:
cell = grid[ni][nj]
if cell == '#':
continue
added_cost = dir_cost
if cell == '@':
added_cost += P
new_cost = cost + added_cost
if new_cost > K:
continue
if new_cost < distance[ni][nj]:
distance[ni][nj] = new_cost
heapq.heappush(heap, (new_cost, ni, nj))
if not found:
print("No")
lam6er