結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 2022-08-03 01:14:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 77,704 KB |
最終ジャッジ日時 | 2024-07-23 19:28:13 |
合計ジャッジ時間 | 5,744 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
H,W = map(int,input().split())U,D,R,L,K,P = map(int,input().split())cost = [U,D,R,L]move = ((-1,0),(1,0),(0,1),(0,-1))def f(n):return int(n)-1xs,ys,xt,yt = map(f,input().split())C = [list(input()) for _ in range(H)]import heapqque = []que.append((0,xs,ys))inf = float("inf")d = [[inf for _ in range(W)] for _ in range(H)]d[xs][ys] = 0need = infwhile len(que) != 0:n,i,j = heapq.heappop(que)if d[i][j] < n:continueif i == xt and j == yt:need = d[i][j]breakfor k in range(4):a,b = move[k]ni,nj = i + a , j + bif ni < 0 or ni >= H or nj < 0 or nj >= W:continueif C[ni][nj] == "#":continuenext = d[i][j] + cost[k]if C[ni][nj] == "@":next += Pif d[ni][nj] <= next:continued[ni][nj] = nextheapq.heappush(que,(next,ni,nj))if need <= K:print("Yes")else:print("No")