結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2022-06-18 01:08:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 1,441 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 79,628 KB |
最終ジャッジ日時 | 2024-10-09 11:41:03 |
合計ジャッジ時間 | 6,906 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
from heapq import heappush, heappopINF = 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-=1C = [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] == '#':continueelse:for cc, xx, yy in zip(cost, x, y):cx, cy = i+xx, j+yyif 0<=cx<H and 0<=cy<W:if C[cx][cy] == '#':continueelif 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] * nhq = [(0, s)] # (distance, node)dist[s] = 0seen = [False] * n # ノードが確定済みかどうか# 経路復元用# prev = [-1]*nwhile hq:dis, v = heappop(hq)if dist[v] < dis:continueseen[v] = Truefor to, cost in adj[v]:if seen[to] == False and dist[v] + cost < dist[to]:dist[to] = dist[v] + cost# prev[to] = vheappush(hq, (dist[to], to))return distd = dijkstra(sx*H+sy, H*W)if d[gx*H+gy]<=K:print('Yes')else:print('No')