結果

問題 No.1638 Robot Maze
ユーザー 👑 H20H20
提出日時 2021-08-06 21:46:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 2,312 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 81,732 KB
実行使用メモリ 98,748 KB
最終ジャッジ日時 2023-10-17 03:05:54
合計ジャッジ時間 11,738 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,488 KB
testcase_01 AC 41 ms
55,488 KB
testcase_02 AC 42 ms
55,488 KB
testcase_03 AC 195 ms
88,636 KB
testcase_04 AC 45 ms
60,848 KB
testcase_05 AC 46 ms
60,848 KB
testcase_06 AC 46 ms
60,848 KB
testcase_07 AC 45 ms
60,848 KB
testcase_08 AC 46 ms
60,848 KB
testcase_09 AC 46 ms
60,848 KB
testcase_10 AC 46 ms
60,848 KB
testcase_11 AC 45 ms
60,848 KB
testcase_12 AC 47 ms
60,848 KB
testcase_13 AC 46 ms
60,848 KB
testcase_14 AC 229 ms
85,372 KB
testcase_15 AC 160 ms
79,688 KB
testcase_16 AC 158 ms
79,688 KB
testcase_17 AC 152 ms
79,860 KB
testcase_18 AC 94 ms
77,588 KB
testcase_19 AC 206 ms
83,508 KB
testcase_20 AC 205 ms
83,508 KB
testcase_21 AC 159 ms
89,432 KB
testcase_22 AC 120 ms
83,196 KB
testcase_23 AC 119 ms
83,192 KB
testcase_24 AC 161 ms
89,436 KB
testcase_25 AC 163 ms
89,432 KB
testcase_26 AC 134 ms
83,472 KB
testcase_27 AC 134 ms
83,468 KB
testcase_28 AC 132 ms
83,644 KB
testcase_29 AC 134 ms
83,644 KB
testcase_30 AC 41 ms
55,556 KB
testcase_31 AC 44 ms
55,556 KB
testcase_32 AC 245 ms
87,004 KB
testcase_33 AC 302 ms
91,976 KB
testcase_34 AC 362 ms
97,604 KB
testcase_35 AC 285 ms
89,864 KB
testcase_36 AC 370 ms
97,660 KB
testcase_37 AC 253 ms
87,544 KB
testcase_38 AC 273 ms
88,268 KB
testcase_39 AC 364 ms
96,840 KB
testcase_40 AC 283 ms
88,496 KB
testcase_41 AC 303 ms
90,204 KB
testcase_42 AC 332 ms
93,316 KB
testcase_43 AC 375 ms
94,028 KB
testcase_44 AC 381 ms
95,456 KB
testcase_45 AC 385 ms
94,956 KB
testcase_46 AC 360 ms
96,576 KB
testcase_47 AC 321 ms
92,768 KB
testcase_48 AC 357 ms
98,324 KB
testcase_49 AC 242 ms
86,996 KB
testcase_50 AC 310 ms
92,488 KB
testcase_51 AC 409 ms
98,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import heapq


class Dijkstra:
    def __init__(self):
        self.e = collections.defaultdict(list)

    def add(self, u, v, d):
        self.e[u].append([v, d])

    def delete(self, u, v):
        self.e[u] = [_ for _ in self.e[u] if _[0] != v]
        self.e[v] = [_ for _ in self.e[v] if _[0] != u]

    def search(self, s):
        """
        :param s: 始点
        :return: 始点から各点までの最短経路
        """
        d = collections.defaultdict(lambda: float('inf'))
        d[s] = 0
        q = []
        heapq.heappush(q, (0, s))
        v = collections.defaultdict(bool)
        while len(q):
            k, u = heapq.heappop(q)
            if v[u]:
                continue
            v[u] = True

            for uv, ud in self.e[u]:
                if v[uv]:
                    continue
                vd = k + ud
                if d[uv] > vd:
                    d[uv] = vd
                    heapq.heappush(q, (vd, uv))

        return d

H,W = map(int, input().split())
U,D,R,L,K,P = map(int, input().split())
sx,sy,tx,ty = map(int, input().split())
sx-=1;sy-=1;tx-=1;ty-=1;
MAP = []
for i in range(H):
    MAP.append(input())
graph = Dijkstra()
for i in range(H):
    for j in range(W):
        if 0<=i-1<H and 0<=j<W:
            if MAP[i-1][j]=='.':
                graph.add((i,j,0),(i-1,j,0),U)
            if MAP[i-1][j]=='@':
                graph.add((i-1,j,1),(i-1,j,0),P)
                graph.add((i,j,0),(i-1,j,1),U)
        if 0<=i+1<H and 0<=j<W:
            if MAP[i+1][j]=='.':
                graph.add((i,j,0),(i+1,j,0),D)
            if MAP[i+1][j]=='@':
                graph.add((i+1,j,1),(i+1,j,0),P)
                graph.add((i,j,0),(i+1,j,1),D)
        if 0<=i<H and 0<=j+1<W:
            if MAP[i][j+1]=='.':
                graph.add((i,j,0),(i,j+1,0),R)
            if MAP[i][j+1]=='@':
                graph.add((i,j+1,1),(i,j+1,0),P)
                graph.add((i,j,0),(i,j+1,1),R)
        if 0<=i<H and 0<=j-1<W:
            if MAP[i][j-1]=='.':
                graph.add((i,j,0),(i,j-1,0),L)
            if MAP[i][j-1]=='@':
                graph.add((i,j-1,1),(i,j-1,0),P)
                graph.add((i,j,0),(i,j-1,1),L)
result = graph.search((sx,sy,0))
if result[(tx,ty,0)]<=K:
    print('Yes')
else:
    print('No')

0