結果
問題 |
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)-1 xs,ys,xt,yt = map(f,input().split()) C = [list(input()) for _ in range(H)] import heapq que = [] que.append((0,xs,ys)) inf = float("inf") d = [[inf for _ in range(W)] for _ in range(H)] d[xs][ys] = 0 need = inf while len(que) != 0: n,i,j = heapq.heappop(que) if d[i][j] < n: continue if i == xt and j == yt: need = d[i][j] break for k in range(4): a,b = move[k] ni,nj = i + a , j + b if ni < 0 or ni >= H or nj < 0 or nj >= W: continue if C[ni][nj] == "#": continue next = d[i][j] + cost[k] if C[ni][nj] == "@": next += P if d[ni][nj] <= next: continue d[ni][nj] = next heapq.heappush(que,(next,ni,nj)) if need <= K: print("Yes") else: print("No")