結果

問題 No.1638 Robot Maze
ユーザー lloyz
提出日時 2023-08-06 21:38:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2024-11-07 00:46:24
合計ジャッジ時間 5,201 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

h, w = map(int, input().split())
u, d, r, l, k, p = map(int, input().split())
si, sj, ti, tj = map(int, input().split())
si -= 1
sj -= 1
ti -= 1
tj -= 1
S = [list(input()) for _ in range(h)]

DP = [[k + 1 for _ in range(w)] for _ in range(h)]
Directions = [(-1, 0), (1, 0), (0, 1), (0, -1)]
C = [u, d, r, l]
DP[si][sj] = 0
H = [(0, si, sj)]
while H:
    cc, ci, cj = heappop(H)
    for i in range(4):
        nc = cc
        di, dj = Directions[i]
        ni, nj = ci + di, cj + dj
        if 0 <= ni < h and 0 <= nj < w:
            if S[ni][nj] == '#':
                continue
            elif S[ni][nj] == '@':
                nc += p
            nc += C[i]
            if nc >= DP[ni][nj]:
                continue
            DP[ni][nj] = nc
            heappush(H, (nc, ni, nj))
if DP[ti][tj] == k + 1:
    print("No")
else:
    print("Yes")
0