結果

問題 No.1638 Robot Maze
ユーザー Akijin_007
提出日時 2025-07-18 23:15:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,880 KB
実行使用メモリ 77,176 KB
最終ジャッジ日時 2025-07-18 23:15:26
合計ジャッジ時間 5,015 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
xs, ys, xt, yt = map(int, input().split())
C = [0] * H

for i in range(H):
    C[i] = input()

xs -= 1
ys -= 1
xt -= 1
yt -= 1

import heapq

q = [(0, xs, ys)]

c = [U, D, R, L]
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
v = [[K+1] * W for i in range(H)]
v[xs][ys] = 0

heapq.heapify(q)

while q:
    d, x, y = heapq.heappop(q)

    if v[x][y] < d:
        continue

    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]

        # print(nx, ny)

        if nx < 0 or H <= nx or ny < 0 or W <= ny:
            continue
        if C[nx][ny] == "#":
            continue

        # print(nx, ny)


        nc = d + c[k]
        if C[nx][ny] == "@":
            nc += P


        if v[nx][ny] > nc:
            v[nx][ny] = nc
            heapq.heappush(q, (nc, nx, ny))

# print(v)

if v[xt][yt] <= K:
    print("Yes")
else:
    print("No")
0