結果

問題 No.1638 Robot Maze
ユーザー moharan627moharan627
提出日時 2021-08-06 22:02:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 2,068 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 79,428 KB
最終ジャッジ日時 2023-10-17 03:24:51
合計ジャッジ時間 6,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,468 KB
testcase_01 AC 38 ms
53,468 KB
testcase_02 AC 38 ms
53,468 KB
testcase_03 AC 104 ms
78,644 KB
testcase_04 AC 39 ms
53,468 KB
testcase_05 AC 40 ms
53,468 KB
testcase_06 AC 39 ms
53,468 KB
testcase_07 AC 40 ms
53,468 KB
testcase_08 AC 39 ms
53,468 KB
testcase_09 AC 39 ms
53,468 KB
testcase_10 AC 40 ms
53,468 KB
testcase_11 AC 39 ms
53,468 KB
testcase_12 AC 40 ms
53,468 KB
testcase_13 AC 39 ms
53,468 KB
testcase_14 AC 129 ms
78,644 KB
testcase_15 AC 104 ms
77,400 KB
testcase_16 AC 104 ms
77,396 KB
testcase_17 AC 104 ms
77,420 KB
testcase_18 AC 57 ms
67,880 KB
testcase_19 AC 103 ms
77,412 KB
testcase_20 AC 104 ms
77,412 KB
testcase_21 AC 68 ms
73,064 KB
testcase_22 AC 67 ms
73,064 KB
testcase_23 AC 68 ms
73,064 KB
testcase_24 AC 68 ms
73,064 KB
testcase_25 AC 67 ms
73,064 KB
testcase_26 AC 77 ms
77,496 KB
testcase_27 AC 78 ms
77,496 KB
testcase_28 AC 77 ms
77,424 KB
testcase_29 AC 76 ms
77,428 KB
testcase_30 AC 38 ms
53,468 KB
testcase_31 AC 39 ms
53,468 KB
testcase_32 AC 115 ms
78,124 KB
testcase_33 AC 127 ms
79,040 KB
testcase_34 AC 121 ms
78,988 KB
testcase_35 AC 128 ms
78,944 KB
testcase_36 AC 130 ms
79,084 KB
testcase_37 AC 125 ms
78,696 KB
testcase_38 AC 137 ms
78,832 KB
testcase_39 AC 132 ms
78,820 KB
testcase_40 AC 136 ms
79,052 KB
testcase_41 AC 128 ms
79,096 KB
testcase_42 AC 136 ms
78,816 KB
testcase_43 AC 160 ms
79,428 KB
testcase_44 AC 157 ms
79,228 KB
testcase_45 AC 147 ms
78,984 KB
testcase_46 AC 149 ms
79,080 KB
testcase_47 AC 127 ms
78,808 KB
testcase_48 AC 122 ms
79,080 KB
testcase_49 AC 135 ms
78,764 KB
testcase_50 AC 129 ms
78,820 KB
testcase_51 AC 150 ms
78,816 KB
権限があれば一括ダウンロードができます

ソースコード

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