結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2023-02-21 23:04:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,713 bytes |
コンパイル時間 | 153 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 79,856 KB |
最終ジャッジ日時 | 2024-07-22 06:59:58 |
合計ジャッジ時間 | 5,942 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
from heapq import heappush, heappopinf = float('inf')def dijkstra(s, g, N):# ゴールがない場合はg=-1とする。def cost(v, m):return v * N + mdist = [inf] * Nmindist = [inf] * Nseen = [False] * NQ = [cost(0, s)]while Q:c, m = divmod(heappop(Q), N)if seen[m]:continueseen[m] = Truedist[m] = cif m == g:return dist#------heapをアップデートする。--------for u, C in G[m]:if seen[u]:continuenewdist = dist[m] + C#------------------------------------if newdist >= mindist[u]:continuemindist[u] = newdistheappush(Q, cost(newdist, u))return distdef f(h, w):return h * W + wH, 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 - 1C = []for i in range(H):C.append(list(input()))N = H * WG = [[] for i in range(N)]for h in range(H):for w in range(W):if C[h][w] == "#":continuefor 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:continueif C[x][y] == "#":continuec = cost[k]if C[x][y] == "@":c += PG[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")