結果

問題 No.1638 Robot Maze
ユーザー irumo8202
提出日時 2022-02-07 12:14:48
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-06-12 03:50:47
合計ジャッジ時間 4,179 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

INF = 1 << 60
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
sx, sy, tx, ty = map(lambda x: int(x) - 1, input().split())

C = [input() for _ in range(H)]

cost = [[INF for _ in range(W)] for _ in range(H)]

cost[sy][sx] = 0
que = deque([(sy, sx)])
direction = [(-1, 0, U), (0, 1, R), (1, 0, D), (0, -1, L)]


def valid(y, x):
    return 0 <= x < W and 0 <= y < H


while que:
    y, x = que.popleft()

    for dy, dx, ct in direction:
        ny, nx = y + dy, x + dx
        if not valid(ny, nx):
            continue

        if cost[ny][nx] != INF:
            continue

        if C[ny][nx] == "#":
            continue

        if C[ny][nx] == "@":
            ct += P

        cost[ny][nx] = min(cost[ny][nx], cost[y][x] + ct)
        que.append((ny, nx))

print("Yes" if cost[ty][tx] <= K else "No")
0