結果

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

ソースコード

diff #

from heapq import heapify, heappop, heappush

def main():
    H,W = map(int,input().split())
    U,D,R,L,K,P = map(int,input().split())
    xs,ys,xt,yt = map(int,input().split())
    xs -= 1; ys -= 1; xt -= 1; yt -= 1
    C = [str(input()) for _ in range(H)]

    INF = pow(10,20)
    #S:start, V: node, E: Edge, G: Graph
    d = [[INF]*W for _ in range(H)]
    d[xs][ys] = 0
    PQ = []
    heappush(PQ,(0,xs,ys))

    dxdy = [(-1,0),(1,0),(0,1),(0,-1)] #U,D,R,L
    Pay = [U,D,R,L]

    while PQ:
        c,vx,vy = heappop(PQ)
        if d[vx][vy] < c:
            continue
        d[vx][vy] = c
        for i in range(4):
            ux = vx + dxdy[i][0]
            uy = vy + dxdy[i][1]
            if ux < 0 or ux >= H or uy < 0 or uy >= W: continue
            if C[ux][uy] == "#": continue #壁
            cost = Pay[i]
            if C[ux][uy] == "@": #壊す
                cost += P
            if d[ux][uy] <= cost + d[vx][vy]:
                continue
            d[ux][uy] = cost + d[vx][vy]
            heappush(PQ,(d[ux][uy],ux,uy))
    #print(d)
    if d[xt][yt] > K:
        print("No")
    else:
        print('Yes')
if __name__ == '__main__':
    main()
0