結果

問題 No.1638 Robot Maze
ユーザー 👑 SPD_9X2
提出日時 2021-08-06 21:46:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 77,228 KB
最終ジャッジ日時 2024-09-17 01:40:09
合計ジャッジ時間 5,708 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from sys import stdin
import heapq

H,W = map(int,stdin.readline().split())

U,D,R,L,K,P = map(int,stdin.readline().split())

xs,ys,xg,yg = map(int,stdin.readline().split())
xs -= 1
ys -= 1
xg -= 1
yg -= 1

C = [stdin.readline()[:-1] for i in range(H)]

d = [[float("inf")] * W for i in range(H)]

q = [(0,xs,ys)]
d[xs][ys] = 0

while q:

    sc,x,y = heapq.heappop(q)

    if d[x][y] != sc:
        continue

    for nx,ny,cost in [(x-1,y,U),(x+1,y,D),(x,y-1,L),(x,y+1,R)]:

        if not (0 <= nx < H and 0 <= ny < W):
            continue

        if C[nx][ny] == "#":
            continue

        if C[nx][ny] == "@":
            cost += P

        if d[nx][ny] > sc + cost:
            d[nx][ny] = sc + cost
            heapq.heappush(q,(d[nx][ny],nx,ny))

if d[xg][yg] <= K:
    print ("Yes")
else:
    print ("No")
0