結果

問題 No.1638 Robot Maze
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-06 22:43:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 871 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 77,244 KB
最終ジャッジ日時 2023-10-17 04:12:11
合計ジャッジ時間 5,568 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,532 KB
testcase_01 AC 39 ms
53,532 KB
testcase_02 AC 38 ms
53,532 KB
testcase_03 AC 84 ms
75,920 KB
testcase_04 AC 40 ms
53,532 KB
testcase_05 AC 40 ms
53,532 KB
testcase_06 AC 40 ms
53,532 KB
testcase_07 AC 40 ms
53,532 KB
testcase_08 AC 40 ms
53,532 KB
testcase_09 AC 40 ms
53,532 KB
testcase_10 AC 40 ms
53,532 KB
testcase_11 AC 40 ms
53,532 KB
testcase_12 AC 40 ms
53,532 KB
testcase_13 AC 40 ms
53,532 KB
testcase_14 AC 90 ms
76,388 KB
testcase_15 AC 74 ms
72,744 KB
testcase_16 AC 74 ms
72,744 KB
testcase_17 AC 78 ms
74,172 KB
testcase_18 AC 40 ms
53,532 KB
testcase_19 AC 73 ms
72,732 KB
testcase_20 AC 73 ms
72,732 KB
testcase_21 AC 54 ms
64,296 KB
testcase_22 AC 54 ms
64,296 KB
testcase_23 AC 53 ms
64,296 KB
testcase_24 AC 53 ms
64,296 KB
testcase_25 AC 53 ms
64,296 KB
testcase_26 AC 63 ms
70,672 KB
testcase_27 AC 63 ms
70,672 KB
testcase_28 AC 62 ms
70,672 KB
testcase_29 AC 61 ms
70,672 KB
testcase_30 AC 38 ms
53,532 KB
testcase_31 AC 38 ms
53,532 KB
testcase_32 AC 98 ms
76,428 KB
testcase_33 AC 112 ms
76,736 KB
testcase_34 AC 98 ms
76,388 KB
testcase_35 AC 113 ms
76,604 KB
testcase_36 AC 107 ms
76,560 KB
testcase_37 AC 97 ms
76,408 KB
testcase_38 AC 98 ms
76,408 KB
testcase_39 AC 104 ms
76,516 KB
testcase_40 AC 111 ms
76,516 KB
testcase_41 AC 104 ms
76,492 KB
testcase_42 AC 113 ms
76,524 KB
testcase_43 AC 119 ms
76,556 KB
testcase_44 AC 113 ms
76,516 KB
testcase_45 AC 128 ms
77,244 KB
testcase_46 AC 103 ms
76,424 KB
testcase_47 AC 93 ms
76,356 KB
testcase_48 AC 111 ms
76,688 KB
testcase_49 AC 96 ms
76,524 KB
testcase_50 AC 112 ms
76,512 KB
testcase_51 AC 120 ms
76,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 18

H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
xs, ys, xt, yt = map(lambda x: int(x)-1, input().split())
C = [input().rstrip() for _ in range(H)]

dydx4 = ((0, 1, R), (1, 0, D), (-1, 0, U), (0, -1, L))
dist = [[inf] * W for _ in range(H)]
dist[xs][ys] = 0

que = [(0, xs, ys)]
while que:
    ds, x, y = heapq.heappop(que)
    if dist[x][y] < ds:
        continue
    for dx, dy, dt in dydx4:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and C[nx][ny] != "#":
            cost = ds + dt + P * (C[nx][ny] == "@")
            if dist[nx][ny] > cost:
                dist[nx][ny] = cost
                heapq.heappush(que, (cost, nx, ny))

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