結果

問題 No.1638 Robot Maze
ユーザー tamatotamato
提出日時 2021-08-06 21:32:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 2,081 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 80,104 KB
最終ジャッジ日時 2023-10-17 02:50:10
合計ジャッジ時間 6,705 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,812 KB
testcase_01 AC 37 ms
53,812 KB
testcase_02 AC 38 ms
53,812 KB
testcase_03 AC 105 ms
78,328 KB
testcase_04 AC 39 ms
53,812 KB
testcase_05 AC 38 ms
53,812 KB
testcase_06 AC 39 ms
53,812 KB
testcase_07 AC 39 ms
53,812 KB
testcase_08 AC 39 ms
53,812 KB
testcase_09 AC 39 ms
53,812 KB
testcase_10 AC 39 ms
53,812 KB
testcase_11 AC 39 ms
53,812 KB
testcase_12 AC 39 ms
53,812 KB
testcase_13 AC 39 ms
53,812 KB
testcase_14 AC 135 ms
78,760 KB
testcase_15 AC 103 ms
77,260 KB
testcase_16 AC 104 ms
77,260 KB
testcase_17 AC 105 ms
77,384 KB
testcase_18 AC 59 ms
68,172 KB
testcase_19 AC 102 ms
77,324 KB
testcase_20 AC 101 ms
77,336 KB
testcase_21 AC 68 ms
72,816 KB
testcase_22 AC 67 ms
72,808 KB
testcase_23 AC 66 ms
72,808 KB
testcase_24 AC 67 ms
72,816 KB
testcase_25 AC 68 ms
72,816 KB
testcase_26 AC 85 ms
77,840 KB
testcase_27 AC 85 ms
77,840 KB
testcase_28 AC 84 ms
77,840 KB
testcase_29 AC 85 ms
77,840 KB
testcase_30 AC 38 ms
53,812 KB
testcase_31 AC 38 ms
53,812 KB
testcase_32 AC 135 ms
78,928 KB
testcase_33 AC 149 ms
79,032 KB
testcase_34 AC 143 ms
79,080 KB
testcase_35 AC 154 ms
79,112 KB
testcase_36 AC 150 ms
79,164 KB
testcase_37 AC 129 ms
78,880 KB
testcase_38 AC 153 ms
79,300 KB
testcase_39 AC 147 ms
79,116 KB
testcase_40 AC 142 ms
78,944 KB
testcase_41 AC 152 ms
79,132 KB
testcase_42 AC 159 ms
79,116 KB
testcase_43 AC 186 ms
79,536 KB
testcase_44 AC 184 ms
79,396 KB
testcase_45 AC 184 ms
80,104 KB
testcase_46 AC 151 ms
79,208 KB
testcase_47 AC 149 ms
79,028 KB
testcase_48 AC 144 ms
79,168 KB
testcase_49 AC 136 ms
78,840 KB
testcase_50 AC 152 ms
79,280 KB
testcase_51 AC 162 ms
79,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline
    import heapq

    def dijkstra(adj, start):
        # adj: [[to, cost] * vertices], 0th index must be empty
        inf = 1 << 60
        dist = [inf] * len(adj)
        dist[start] = 0
        q = []
        heapq.heappush(q, (0, start))
        while q:
            min_dist, v_from = heapq.heappop(q)
            if min_dist > dist[v_from]:
                continue
            v_tos = adj[v_from]
            for v_to, cost in v_tos:
                if min_dist + cost < dist[v_to]:
                    dist[v_to] = min_dist + cost
                    heapq.heappush(q, (dist[v_to], v_to))
        return dist

    H, W = map(int, input().split())
    U, D, R, L, K, P = map(int, input().split())
    adj = [[] for _ in range(H * W + 1)]
    hs, ws, ht, wt = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    for h in range(H):
        for w in range(W-1):
            hw = h*W + w + 1
            # R
            if grid[h][w+1] == ".":
                adj[hw].append((hw+1, R))
            elif grid[h][w+1] == "@":
                adj[hw].append((hw+1, R+P))
            # L
            if grid[h][w] == ".":
                adj[hw+1].append((hw, L))
            elif grid[h][w] == "@":
                adj[hw+1].append((hw, L+P))

    for w in range(W):
        for h in range(H-1):
            hw = h*W + w + 1
            # D
            if grid[h + 1][w] == ".":
                adj[hw].append((hw + W, D))
            elif grid[h + 1][w] == "@":
                adj[hw].append((hw + W, D + P))
            # U
            if grid[h][w] == ".":
                adj[hw + W].append((hw, U))
            elif grid[h][w] == "@":
                adj[hw + W].append((hw, U + P))

    hs -= 1
    ht -= 1
    ws -= 1
    wt -= 1
    hw_s = hs*W + ws + 1
    hw_t = ht*W + wt + 1
    ans = dijkstra(adj, hw_s)[hw_t]
    if ans <= K:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
0