結果

問題 No.1638 Robot Maze
コンテスト
ユーザー DrDrpilot
提出日時 2022-01-20 14:57:46
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,365 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,041 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-05-17 11:51:22
合計ジャッジ時間 8,815 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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