結果

問題 No.1638 Robot Maze
ユーザー 👑 H20H20
提出日時 2021-08-06 21:44:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,312 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 99,204 KB
最終ジャッジ日時 2023-10-17 03:02:25
合計ジャッジ時間 12,646 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,544 KB
testcase_01 AC 39 ms
55,544 KB
testcase_02 AC 39 ms
55,544 KB
testcase_03 AC 263 ms
88,732 KB
testcase_04 AC 45 ms
60,848 KB
testcase_05 AC 44 ms
60,848 KB
testcase_06 AC 44 ms
60,848 KB
testcase_07 AC 44 ms
60,848 KB
testcase_08 AC 44 ms
60,848 KB
testcase_09 AC 44 ms
60,848 KB
testcase_10 AC 43 ms
60,848 KB
testcase_11 AC 45 ms
60,848 KB
testcase_12 AC 44 ms
60,848 KB
testcase_13 AC 43 ms
60,848 KB
testcase_14 AC 213 ms
85,396 KB
testcase_15 AC 153 ms
79,728 KB
testcase_16 AC 154 ms
79,732 KB
testcase_17 AC 145 ms
79,904 KB
testcase_18 AC 91 ms
77,596 KB
testcase_19 AC 200 ms
83,552 KB
testcase_20 AC 200 ms
83,552 KB
testcase_21 AC 159 ms
89,448 KB
testcase_22 AC 114 ms
83,204 KB
testcase_23 AC 116 ms
83,200 KB
testcase_24 AC 155 ms
89,444 KB
testcase_25 AC 155 ms
89,444 KB
testcase_26 AC 130 ms
83,520 KB
testcase_27 AC 131 ms
83,512 KB
testcase_28 AC 130 ms
83,684 KB
testcase_29 AC 130 ms
83,660 KB
testcase_30 AC 40 ms
55,556 KB
testcase_31 WA -
testcase_32 AC 240 ms
87,060 KB
testcase_33 AC 313 ms
92,056 KB
testcase_34 AC 386 ms
98,476 KB
testcase_35 AC 300 ms
90,052 KB
testcase_36 AC 382 ms
98,148 KB
testcase_37 AC 236 ms
87,652 KB
testcase_38 AC 242 ms
88,288 KB
testcase_39 AC 377 ms
97,804 KB
testcase_40 AC 285 ms
88,800 KB
testcase_41 AC 311 ms
90,620 KB
testcase_42 AC 331 ms
92,748 KB
testcase_43 AC 344 ms
93,728 KB
testcase_44 AC 385 ms
94,924 KB
testcase_45 AC 380 ms
94,828 KB
testcase_46 AC 356 ms
96,300 KB
testcase_47 AC 314 ms
92,988 KB
testcase_48 AC 356 ms
98,268 KB
testcase_49 AC 233 ms
86,992 KB
testcase_50 AC 325 ms
93,388 KB
testcase_51 AC 408 ms
99,204 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),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),D)
result = graph.search((sx,sy,0))
if result[(tx,ty,0)]<=K:
    print('Yes')
else:
    print('No')

0