結果

問題 No.1638 Robot Maze
ユーザー Mine
提出日時 2021-09-10 13:00:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 78,068 KB
最終ジャッジ日時 2025-01-03 00:22:01
合計ジャッジ時間 7,528 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def main():
    H, W = map(int, input().split())
    u,d,r,l,k,p = map(int, input().split())
    x1, x2, y1, y2 = [i-1 for i in list(map(int, input().split()))]
    c = [input() for i in range(H)]
    seen = [[False]*W for _ in range(H)]
    costs = [u, d, r, l]
    directions = [(-1, 0), (1, 0), (0, 1), (0, -1)]

    hq = []
    hq.append((0, x1, x2))
    while hq:
        cost, h, w = heapq.heappop(hq)
        if h == y1 and w == y2:
            if cost <= k:
                return True
            else:
                return False
        if not seen[h][w]:
            seen[h][w] = True
            for idx, (dh, dw) in enumerate(directions):
                if 0 <= h+dh < H and 0 <= w+dw < W and not seen[h+dh][w+dw]:
                    if c[h+dh][w+dw] == ".":
                        heapq.heappush(hq, (cost + costs[idx], h+dh, w+dw))
                    elif c[h+dh][w+dw] == "@":
                        heapq.heappush(hq, (cost + costs[idx] + p, h+dh, w+dw))
    return False

if main():
    print("Yes")
else:
    print("No")
0