結果

問題 No.1638 Robot Maze
ユーザー rlangevinrlangevin
提出日時 2023-02-21 23:04:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,713 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 80,972 KB
最終ジャッジ日時 2023-09-29 12:39:39
合計ジャッジ時間 8,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,488 KB
testcase_01 AC 65 ms
71,448 KB
testcase_02 AC 62 ms
71,480 KB
testcase_03 AC 103 ms
80,528 KB
testcase_04 AC 64 ms
71,404 KB
testcase_05 AC 68 ms
71,572 KB
testcase_06 AC 71 ms
71,652 KB
testcase_07 AC 67 ms
71,568 KB
testcase_08 AC 64 ms
71,488 KB
testcase_09 AC 61 ms
71,540 KB
testcase_10 AC 61 ms
71,480 KB
testcase_11 AC 66 ms
71,188 KB
testcase_12 AC 64 ms
71,192 KB
testcase_13 AC 61 ms
71,196 KB
testcase_14 AC 104 ms
79,580 KB
testcase_15 AC 116 ms
78,648 KB
testcase_16 AC 120 ms
78,848 KB
testcase_17 AC 116 ms
79,196 KB
testcase_18 AC 91 ms
78,568 KB
testcase_19 AC 107 ms
79,516 KB
testcase_20 AC 103 ms
79,456 KB
testcase_21 AC 91 ms
79,404 KB
testcase_22 AC 90 ms
79,400 KB
testcase_23 AC 97 ms
79,552 KB
testcase_24 AC 93 ms
79,640 KB
testcase_25 AC 93 ms
79,364 KB
testcase_26 AC 91 ms
79,472 KB
testcase_27 AC 89 ms
79,464 KB
testcase_28 AC 89 ms
79,572 KB
testcase_29 AC 92 ms
79,540 KB
testcase_30 AC 63 ms
71,600 KB
testcase_31 AC 64 ms
71,604 KB
testcase_32 AC 118 ms
79,556 KB
testcase_33 AC 131 ms
80,664 KB
testcase_34 AC 133 ms
80,972 KB
testcase_35 AC 129 ms
80,376 KB
testcase_36 AC 125 ms
80,544 KB
testcase_37 AC 123 ms
80,112 KB
testcase_38 AC 90 ms
78,932 KB
testcase_39 AC 128 ms
80,672 KB
testcase_40 AC 125 ms
80,344 KB
testcase_41 AC 129 ms
80,340 KB
testcase_42 AC 123 ms
79,544 KB
testcase_43 AC 137 ms
80,640 KB
testcase_44 AC 148 ms
80,668 KB
testcase_45 AC 113 ms
80,220 KB
testcase_46 AC 123 ms
80,620 KB
testcase_47 AC 129 ms
80,076 KB
testcase_48 AC 128 ms
80,628 KB
testcase_49 AC 128 ms
80,136 KB
testcase_50 AC 116 ms
80,320 KB
testcase_51 AC 131 ms
80,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
inf = float('inf')


def dijkstra(s, g, N):
    # ゴールがない場合はg=-1とする。

    def cost(v, m):
        return v * N + m

    dist = [inf] * N
    mindist = [inf] * N
    seen = [False] * N
    Q = [cost(0, s)]
    while Q:
        c, m = divmod(heappop(Q), N)
        if seen[m]:
            continue
        seen[m] = True
        dist[m] = c
        if m == g:
            return dist

        #------heapをアップデートする。--------
        for u, C in G[m]:
            if seen[u]:
                continue
            newdist = dist[m] + C

            #------------------------------------
            if newdist >= mindist[u]:
                continue
            mindist[u] = newdist
            heappush(Q, cost(newdist, u))
    return dist

def f(h, w):
    return h * W + w

H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
cost = [D, R, U, L]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
sx, sy, gx, gy = map(int, input().split())
sx, sy, gx, gy = sx - 1, sy - 1, gx - 1, gy - 1
C = []
for i in range(H):
    C.append(list(input()))
    
N = H * W
G = [[] for i in range(N)]
for h in range(H):
    for w in range(W):
        if C[h][w] == "#":
            continue
        for k in range(4):
            x = h + dx[k]
            y = w + dy[k]
            if x < 0 or x > H - 1 or y < 0 or y > W - 1:
                continue
            if C[x][y] == "#":
                continue
            c = cost[k]
            if C[x][y] == "@":
                c += P
            G[f(h,w)].append((f(x,y), c))
            
D = dijkstra(f(sx, sy), f(gx, gy), N)
if D[f(gx, gy)] <= K:
    print("Yes")
else:
    print("No")
0