結果

問題 No.1638 Robot Maze
ユーザー ThetaTheta
提出日時 2024-04-16 18:51:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,264 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 82,752 KB
実行使用メモリ 79,004 KB
最終ジャッジ日時 2024-04-16 18:51:14
合計ジャッジ時間 6,558 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,736 KB
testcase_01 AC 45 ms
53,376 KB
testcase_02 AC 43 ms
52,864 KB
testcase_03 AC 105 ms
76,928 KB
testcase_04 AC 43 ms
53,120 KB
testcase_05 AC 43 ms
53,644 KB
testcase_06 AC 43 ms
53,760 KB
testcase_07 AC 43 ms
53,120 KB
testcase_08 AC 42 ms
52,992 KB
testcase_09 AC 42 ms
52,864 KB
testcase_10 AC 42 ms
53,376 KB
testcase_11 AC 43 ms
53,504 KB
testcase_12 AC 44 ms
53,376 KB
testcase_13 AC 43 ms
53,760 KB
testcase_14 AC 108 ms
76,928 KB
testcase_15 AC 103 ms
76,928 KB
testcase_16 AC 103 ms
76,928 KB
testcase_17 AC 105 ms
76,928 KB
testcase_18 AC 47 ms
59,392 KB
testcase_19 AC 104 ms
77,244 KB
testcase_20 AC 103 ms
77,308 KB
testcase_21 AC 63 ms
67,584 KB
testcase_22 AC 63 ms
67,328 KB
testcase_23 AC 63 ms
67,840 KB
testcase_24 AC 63 ms
66,944 KB
testcase_25 AC 69 ms
66,944 KB
testcase_26 AC 71 ms
72,192 KB
testcase_27 AC 71 ms
73,088 KB
testcase_28 AC 74 ms
73,764 KB
testcase_29 AC 74 ms
73,600 KB
testcase_30 AC 42 ms
53,376 KB
testcase_31 AC 41 ms
52,992 KB
testcase_32 AC 116 ms
77,208 KB
testcase_33 AC 132 ms
78,172 KB
testcase_34 AC 105 ms
77,312 KB
testcase_35 AC 125 ms
77,568 KB
testcase_36 AC 130 ms
77,416 KB
testcase_37 AC 134 ms
77,140 KB
testcase_38 AC 123 ms
76,772 KB
testcase_39 AC 114 ms
77,520 KB
testcase_40 AC 133 ms
77,720 KB
testcase_41 AC 119 ms
77,372 KB
testcase_42 AC 133 ms
77,960 KB
testcase_43 AC 163 ms
77,820 KB
testcase_44 AC 173 ms
78,880 KB
testcase_45 AC 187 ms
79,004 KB
testcase_46 AC 125 ms
77,592 KB
testcase_47 AC 113 ms
76,748 KB
testcase_48 AC 122 ms
77,212 KB
testcase_49 AC 116 ms
77,236 KB
testcase_50 AC 141 ms
77,300 KB
testcase_51 AC 158 ms
77,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush
from math import inf
DIJ = ((0, 1), (1, 0), (0, -1), (-1, 0))


def main():
    H, W = map(int, input().split())
    U, D, R, L, K, P = map(int, input().split())
    move_costs = (R, D, L, U)
    xs, ys, xt, yt = map(lambda n: int(n) - 1, input().split())
    board = [list(input()) for _ in range(H)]

    cost = [[inf for _ in range(W)] for _ in range(H)]
    cost[xs][ys] = 0
    queue = [(0, (xs, ys))]
    while queue:
        c_d, c_pos = heappop(queue)
        if c_d > cost[c_pos[0]][c_pos[1]]:
            continue
        for dij, m_cost in zip(DIJ, move_costs):
            n_pos = (c_pos[0] + dij[0], c_pos[1] + dij[1])
            if not (0 <= n_pos[0] < H and 0 <= n_pos[1] < W):
                continue
            if board[n_pos[0]][n_pos[1]] == "#":
                continue
            broken_cost = 0
            if board[n_pos[0]][n_pos[1]] == "@":
                broken_cost = P

            if cost[n_pos[0]][n_pos[1]] > c_d + m_cost + broken_cost:
                cost[n_pos[0]][n_pos[1]] = c_d + m_cost + broken_cost
                heappush(queue, (cost[n_pos[0]][n_pos[1]], n_pos))

    if cost[xt][yt] <= K:
        print("Yes")
    else:
        print("No")


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