結果

問題 No.1638 Robot Maze
ユーザー AEnAEn
提出日時 2022-06-18 01:08:07
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,441 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 80,972 KB
最終ジャッジ日時 2023-07-30 16:29:27
合計ジャッジ時間 10,329 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,076 KB
testcase_01 AC 76 ms
71,468 KB
testcase_02 AC 74 ms
71,332 KB
testcase_03 AC 145 ms
80,824 KB
testcase_04 AC 76 ms
71,148 KB
testcase_05 AC 75 ms
71,508 KB
testcase_06 AC 76 ms
71,236 KB
testcase_07 AC 76 ms
71,508 KB
testcase_08 AC 77 ms
71,076 KB
testcase_09 AC 76 ms
71,296 KB
testcase_10 AC 76 ms
71,288 KB
testcase_11 AC 75 ms
71,404 KB
testcase_12 AC 75 ms
71,524 KB
testcase_13 AC 76 ms
71,076 KB
testcase_14 AC 155 ms
79,464 KB
testcase_15 AC 146 ms
79,532 KB
testcase_16 AC 145 ms
79,504 KB
testcase_17 AC 138 ms
79,824 KB
testcase_18 AC 96 ms
76,572 KB
testcase_19 AC 138 ms
79,516 KB
testcase_20 AC 139 ms
79,608 KB
testcase_21 AC 109 ms
78,708 KB
testcase_22 AC 108 ms
79,088 KB
testcase_23 AC 109 ms
79,080 KB
testcase_24 AC 110 ms
79,060 KB
testcase_25 AC 111 ms
78,904 KB
testcase_26 AC 113 ms
78,744 KB
testcase_27 AC 115 ms
78,780 KB
testcase_28 AC 112 ms
78,860 KB
testcase_29 AC 117 ms
78,792 KB
testcase_30 AC 77 ms
71,384 KB
testcase_31 AC 75 ms
71,368 KB
testcase_32 AC 161 ms
79,920 KB
testcase_33 AC 161 ms
80,552 KB
testcase_34 AC 164 ms
80,288 KB
testcase_35 AC 165 ms
80,000 KB
testcase_36 AC 168 ms
80,752 KB
testcase_37 AC 168 ms
79,736 KB
testcase_38 AC 191 ms
80,432 KB
testcase_39 AC 170 ms
80,380 KB
testcase_40 AC 177 ms
80,072 KB
testcase_41 AC 168 ms
80,508 KB
testcase_42 AC 174 ms
80,012 KB
testcase_43 AC 197 ms
80,460 KB
testcase_44 AC 203 ms
80,612 KB
testcase_45 AC 188 ms
80,300 KB
testcase_46 AC 182 ms
80,972 KB
testcase_47 AC 165 ms
80,064 KB
testcase_48 AC 158 ms
80,216 KB
testcase_49 AC 173 ms
79,780 KB
testcase_50 AC 162 ms
80,236 KB
testcase_51 AC 191 ms
80,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

x = [1, 0, 0, -1]
y = [0, 1, -1, 0]
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
cost = [D, R, L, U]
sx, sy, gx, gy = map(int, input().split())
sx-=1;sy-=1;gx-=1;gy-=1
C = [list(input()) for _ in range(H)]
adj = [list() for _ in range(H*W)]
for i in range(H):
    for j in range(W):
        if C[i][j] == '#':
            continue
        else:
            for cc, xx, yy in zip(cost, x, y):
                cx, cy = i+xx, j+yy
                if 0<=cx<H and 0<=cy<W:
                    if C[cx][cy] == '#':
                        continue
                    elif C[cx][cy] == '.':
                        adj[i*H+j].append((cx*H+cy, cc))
                    else:
                        adj[i*H+j].append((cx*H+cy, P+cc))

def dijkstra(s, n):
    dist = [INF] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    # 経路復元用
    # prev = [-1]*n
    while hq:
        dis, v = heappop(hq)
        if dist[v] < dis:
            continue
        seen[v] = True
        for to, cost in adj[v]:
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                # prev[to] = v
                heappush(hq, (dist[to], to))
    return dist
d = dijkstra(sx*H+sy, H*W)
if d[gx*H+gy]<=K:
    print('Yes')
else:
    print('No')
0