結果

問題 No.1638 Robot Maze
ユーザー tonyu0
提出日時 2022-09-21 18:08:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-12-22 04:16:18
合計ジャッジ時間 4,796 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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(lambda x: int(x)-1,input().split())
s=[input() for _ in range(h)]

dx=[0, 1, 0, -1]
dy=[1, 0, -1, 0]
cs=[r, d,  l, u]

import heapq
pq=[]
heapq.heapify(pq)
n=h*w
cost=[1e18]*n
cost[xs*w+ys]=0
heapq.heappush(pq,[0,xs*w+ys])
while len(pq) > 0:
    c,v=heapq.heappop(pq)
    x,y=divmod(v, w)
    for i in range(4):
        nx=x+dx[i]
        ny=y+dy[i]
        if 0<=nx<h and 0<=ny<w and cost[nx*w+ny]==1e18 and s[nx][ny]!='#':
            cost[nx*w+ny]=c+cs[i]
            if s[nx][ny]=='@':
                cost[nx*w+ny] += p
            heapq.heappush(pq, [cost[nx*w+ny], nx*w+ny])
if cost[xt*w+yt] <= k:
    print('Yes')
else:print('No')
0