結果

問題 No.1638 Robot Maze
ユーザー moharan627
提出日時 2021-08-06 22:02:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 2,068 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,324 KB
実行使用メモリ 79,636 KB
最終ジャッジ日時 2024-09-17 02:01:17
合計ジャッジ時間 6,366 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
#from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    H,W = MI()
    U,D,R,L,K,P =MI()
    Xs,Ys,Xt,Yt = MI()
    Map = [["#"]*(W+2) for _ in range(H+2)]
    for h in range(1,H+1):
        Tmp = LC()
        Map[h] = ["#"] + Tmp + ["#"]
    Graph = [[] for n in range((H+1)*(W+1) + 100)]
    Vec = [(0,1,R),(0,-1,L),(1,0,D),(-1,0,U)]
    for h in range(1,H+1):
        for w in range(1,W+1):
            if Map[h][w] == "#":continue
            A = H*(h-1) + (w-1)
            for di,dj,cost in Vec:
                dh = h+di
                dw = w+dj
                if Map[dh][dw] == "#":continue
                if Map[dh][dw] == "@":cost += P
                B = H*(dh-1) + dw-1
                Graph[A].append((B,cost))
    Start = H*(Xs-1) + Ys -1
    Goal = H*(Xt-1) + Yt -1
    from heapq import heappush, heappop
    def dijkstra(s, n):  # (始点, ノード数)
        dist = [INF] * n
        hq = [(0, s)]  # (distance, node)
        dist[s] = 0
        seen = [False] * n  # ノードが確定済みかどうか
        while hq:
            v = heappop(hq)[1]  # ノードを pop する
            if seen[v]:
                continue
            seen[v] = True
            for to, cost in Graph[v]:  # ノード v に隣接しているノードに対して
                if seen[to] == False and dist[v] + cost < dist[to]:
                    dist[to] = dist[v] + cost
                    heappush(hq, (dist[to], to))
        return dist
    Dist = dijkstra(Start,(H+1)*(W+1) + 100)
    #print(Dist)
    #print(Dist[Goal])
    if Dist[Goal] <= K:
        print("Yes")
    else:
        print("No")
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0