結果

問題 No.1638 Robot Maze
ユーザー kohei2019
提出日時 2022-06-26 10:08:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,636 KB
最終ジャッジ日時 2024-11-16 10:31:40
合計ジャッジ時間 5,799 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

H,W = map(int,input().split())
U,D,R,L,K,P = map(int,input().split())
move = [(-1,0,U),(1,0,D),(0,1,R),(0,-1,L)]
xs,ys,xt,yt = map(int,input().split())
xs,ys,xt,yt = xs-1,ys-1,xt-1,yt-1
lsHW = [input() for i in range(H)]

h = [(0,xs,ys)]
INF = float('INF')
lscost = [[INF]*(W) for i in range(H)]
lscost[xs][ys] = 0
while h:
    co,x,y = heapq.heappop(h)
    for dx,dy,c in move:
        if 0<= x+dx < H and 0<= y+dy < W:
            if lsHW[x+dx][y+dy] == '#':
                continue
            if lsHW[x+dx][y+dy] == '@':
                if lscost[x+dx][y+dy] > lscost[x][y] + c + P:
                    lscost[x+dx][y+dy] = lscost[x][y] + c + P
                    heapq.heappush(h,(lscost[x+dx][y+dy],x+dx,y+dy))
            else:
                if lscost[x+dx][y+dy] > lscost[x][y] + c:
                    lscost[x+dx][y+dy] = lscost[x][y] + c
                    heapq.heappush(h,(lscost[x+dx][y+dy],x+dx,y+dy))
if lscost[xt][yt] <= K:
    print('Yes')
else:
    print('No')
0