結果

問題 No.1638 Robot Maze
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-17 19:50:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 1,765 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 80,448 KB
最終ジャッジ日時 2024-04-19 02:16:14
合計ジャッジ時間 8,793 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
52,992 KB
testcase_01 AC 47 ms
52,608 KB
testcase_02 AC 46 ms
52,992 KB
testcase_03 AC 127 ms
78,848 KB
testcase_04 AC 47 ms
53,504 KB
testcase_05 AC 48 ms
53,248 KB
testcase_06 AC 48 ms
53,120 KB
testcase_07 AC 49 ms
52,992 KB
testcase_08 AC 48 ms
53,376 KB
testcase_09 AC 48 ms
53,120 KB
testcase_10 AC 48 ms
53,248 KB
testcase_11 AC 47 ms
53,632 KB
testcase_12 AC 47 ms
53,248 KB
testcase_13 AC 47 ms
53,248 KB
testcase_14 AC 165 ms
79,412 KB
testcase_15 AC 128 ms
77,596 KB
testcase_16 AC 129 ms
77,600 KB
testcase_17 AC 126 ms
77,760 KB
testcase_18 AC 84 ms
68,992 KB
testcase_19 AC 128 ms
78,008 KB
testcase_20 AC 127 ms
77,696 KB
testcase_21 AC 87 ms
73,088 KB
testcase_22 AC 85 ms
72,448 KB
testcase_23 AC 85 ms
72,192 KB
testcase_24 AC 87 ms
73,088 KB
testcase_25 AC 90 ms
72,832 KB
testcase_26 AC 100 ms
78,080 KB
testcase_27 AC 104 ms
77,952 KB
testcase_28 AC 107 ms
77,952 KB
testcase_29 AC 109 ms
78,208 KB
testcase_30 AC 50 ms
52,608 KB
testcase_31 AC 49 ms
52,736 KB
testcase_32 AC 171 ms
79,244 KB
testcase_33 AC 190 ms
79,404 KB
testcase_34 AC 190 ms
79,564 KB
testcase_35 AC 183 ms
79,272 KB
testcase_36 AC 196 ms
79,252 KB
testcase_37 AC 160 ms
79,352 KB
testcase_38 AC 181 ms
79,532 KB
testcase_39 AC 187 ms
79,804 KB
testcase_40 AC 207 ms
79,756 KB
testcase_41 AC 203 ms
79,548 KB
testcase_42 AC 200 ms
79,216 KB
testcase_43 AC 229 ms
80,400 KB
testcase_44 AC 213 ms
80,008 KB
testcase_45 AC 235 ms
80,448 KB
testcase_46 AC 188 ms
79,420 KB
testcase_47 AC 183 ms
79,208 KB
testcase_48 AC 190 ms
79,492 KB
testcase_49 AC 184 ms
79,248 KB
testcase_50 AC 202 ms
79,280 KB
testcase_51 AC 187 ms
79,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
INF = 10**18
def dijkstra(s, edge):
    n = len(edge)
    dist = [INF]*n
    dist[s] = 0
    edgelist = []
    heapq.heappush(edgelist,(dist[s], s))
    while edgelist:
        minedge = heapq.heappop(edgelist)
        if dist[minedge[1]] < minedge[0]:
            continue
        v = minedge[1]
        for e in edge[v]:
            if dist[e[1]] > dist[v]+e[0]:
                dist[e[1]] = dist[v]+e[0]
                heapq.heappush(edgelist,(dist[e[1]], e[1]))
    return dist

import sys
import io, os
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

h, w = map(int, input().split())
u, d, r, l, k, p = map(int, input().split())
g = [[] for i in range(h*w)]
xs, ys, xt, yt = map(int, input().split())
xs, ys, xt, yt = xs-1, ys-1, xt-1, yt-1
C = [str(input().rstrip()) for i in range(h)]
for i in range(h):
    for j in range(w):
        a = i*w+j
        if i > 0:
            b = (i-1)*w+j
            if C[i-1][j] == '.':
                g[a].append((u, b))
            elif  C[i-1][j] == '@':
                g[a].append((u+p, b))
        if i < h-1:
            b = (i+1)*w+j
            if C[i+1][j] == '.':
                g[a].append((d, b))
            elif  C[i+1][j] == '@':
                g[a].append((d+p, b))
        if j < w-1:
            b = i*w+j+1
            if C[i][j+1] == '.':
                g[a].append((r, b))
            elif  C[i][j+1] == '@':
                g[a].append((r+p, b))
        if j > 0:
            b = i*w+j-1
            if C[i][j-1] == '.':
                g[a].append((l, b))
            elif  C[i][j-1] == '@':
                g[a].append((l+p, b))

s = xs*w+ys
t = xt*w+yt
D = dijkstra(s, g)
#print(D[t])
if D[t] <= k:
    print('Yes')
else:
    print('No')
0