結果

問題 No.1638 Robot Maze
ユーザー DrDrpilot
提出日時 2022-01-20 14:57:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-11-23 19:26:04
合計ジャッジ時間 5,309 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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())
sy,sx,gy,gx=map(int,input().split())
sy-=1;sx-=1;gy-=1;gx-=1
g=[input() for _ in range(h)]
inf=float('inf')
dst=[[inf]*w for _ in range(h)]
confirmed=[[False]*w for _ in range(h)]
q=[]
heapq.heappush(q,(0,sy,sx))
while q:
    cost,y,x=heapq.heappop(q)
    if confirmed[y][x]:
        continue
    confirmed[y][x]=True
    dst[y][x]=cost
    dy=[-1,1,0,0]
    dx=[0,0,1,-1]
    move_cost=[u,d,r,l]
    if y!=0:
        if not confirmed[y-1][x]:
            if g[y-1][x]=='.':
                heapq.heappush(q,(cost+u,y-1,x))
            elif g[y-1][x]=='@':
                heapq.heappush(q,(cost+u+p,y-1,x))
    if y!=h-1:
        if not confirmed[y+1][x]:
            if g[y+1][x]=='.':
                heapq.heappush(q,(cost+d,y+1,x))
            elif g[y+1][x]=='@':
                heapq.heappush(q,(cost+d+p,y+1,x))
    if x!=0:
        if not confirmed[y][x-1]:
            if g[y][x-1]=='.':
                heapq.heappush(q,(cost+l,y,x-1))
            elif g[y][x-1]=='@':
                heapq.heappush(q,(cost+l+p,y,x-1)) 
    if x!=w-1:
        if not confirmed[y][x+1]:
            if g[y][x+1]=='.':
                heapq.heappush(q,(cost+r,y,x+1))
            elif g[y][x+1]=='@':
                heapq.heappush(q,(cost+r+p,y,x+1))
print('Yes' if dst[gy][gx]<=k else 'No')
0