結果

問題 No.1638 Robot Maze
ユーザー nephrologistnephrologist
提出日時 2021-08-06 21:56:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 77,424 KB
最終ジャッジ日時 2023-10-17 03:18:26
合計ジャッジ時間 4,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,468 KB
testcase_01 AC 39 ms
53,468 KB
testcase_02 AC 39 ms
53,468 KB
testcase_03 AC 94 ms
76,376 KB
testcase_04 AC 38 ms
53,468 KB
testcase_05 AC 39 ms
53,468 KB
testcase_06 AC 40 ms
53,468 KB
testcase_07 AC 40 ms
53,468 KB
testcase_08 AC 40 ms
53,468 KB
testcase_09 AC 40 ms
53,468 KB
testcase_10 AC 39 ms
53,468 KB
testcase_11 AC 40 ms
53,468 KB
testcase_12 AC 39 ms
53,468 KB
testcase_13 AC 39 ms
53,468 KB
testcase_14 AC 78 ms
74,204 KB
testcase_15 AC 93 ms
76,452 KB
testcase_16 AC 90 ms
76,376 KB
testcase_17 AC 93 ms
76,368 KB
testcase_18 AC 41 ms
55,516 KB
testcase_19 AC 74 ms
72,476 KB
testcase_20 AC 72 ms
72,476 KB
testcase_21 AC 39 ms
53,468 KB
testcase_22 AC 53 ms
66,236 KB
testcase_23 AC 53 ms
66,236 KB
testcase_24 AC 52 ms
64,188 KB
testcase_25 AC 52 ms
64,188 KB
testcase_26 AC 56 ms
68,368 KB
testcase_27 AC 56 ms
68,368 KB
testcase_28 AC 57 ms
70,416 KB
testcase_29 AC 57 ms
70,416 KB
testcase_30 AC 39 ms
53,468 KB
testcase_31 AC 39 ms
53,468 KB
testcase_32 AC 113 ms
76,436 KB
testcase_33 AC 121 ms
77,064 KB
testcase_34 AC 118 ms
76,608 KB
testcase_35 AC 128 ms
77,424 KB
testcase_36 AC 116 ms
76,608 KB
testcase_37 AC 116 ms
76,504 KB
testcase_38 AC 40 ms
53,468 KB
testcase_39 AC 109 ms
76,548 KB
testcase_40 AC 109 ms
76,428 KB
testcase_41 AC 136 ms
77,260 KB
testcase_42 AC 39 ms
53,468 KB
testcase_43 AC 39 ms
53,468 KB
testcase_44 AC 40 ms
53,468 KB
testcase_45 AC 39 ms
53,468 KB
testcase_46 AC 39 ms
53,468 KB
testcase_47 AC 40 ms
53,468 KB
testcase_48 AC 39 ms
53,468 KB
testcase_49 AC 45 ms
59,292 KB
testcase_50 AC 39 ms
53,468 KB
testcase_51 AC 39 ms
53,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappop, heappush

input = sys.stdin.readline

h, w = map(int, input().split())


def idxtoxy(idx):
    return idx // w, idx % w


def xytoidx(x, y):
    return x * w + y


n = h * w
U, D, R, L, K, P = map(int, input().split())
sx, sy, gx, gy = map(int, input().split())

graph = [list(input()) for _ in range(h)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

start = xytoidx(sx - 1, sy - 1)
goal = xytoidx(gx - 1, gy - 1)

cost = [D, R, U, L]


def dijkstra(start, graph):
    infi = 1 << 80
    mask = 1 << 18
    pq = []
    dist = [infi] * n
    heappush(pq, 0 * mask + start)
    while pq:
        temp = heappop(pq)
        d, v = temp // mask, temp & (mask - 1)
        if dist[v] <= d:
            continue
        if d > K:
            continue
        x, y = idxtoxy(v)
        dist[v] = d
        if v == goal:
            return dist[goal]
        for t in range(4):
            nx = x + dx[t]
            ny = y + dy[t]
            if 0 <= nx < h and 0 <= ny < w:
                delta = cost[t]
                if graph[nx][ny] == "#":
                    continue
                if graph[nx][ny] == "@":
                    delta += P
                u = xytoidx(nx, ny)
                nd = d + delta
                if dist[u] > nd:
                    heappush(pq, nd * mask + u)
    return dist[goal]


print("No" if dijkstra(start, graph) == 1 << 80 else "Yes")
0