結果
問題 | No.1638 Robot Maze |
ユーザー | defilement |
提出日時 | 2021-08-06 22:06:46 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,643 bytes |
コンパイル時間 | 311 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-09-17 02:06:47 |
合計ジャッジ時間 | 3,871 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
h,w = map(int,input().split()) u,d,r,l,k,p = map(int,input().split()) sy,sx,gy,gx = map(int,input().split()) from sys import stdin grid = [stdin.readline()[:-1] for _ in range(h)] import heapq for i in range(h): grid[i] = list(grid[i]) hq = [(0,sx,sy)] heapq.heapify(hq) shortest = [[False for _ in range(w)] for _ in range(h)] answer = [[10**13+1 for _ in range(w)] for _ in range(h)] while hq: cost,xax,yax = heapq.heappop(hq) if shortest[yax-1][xax-1]: continue shortest[yax-1][xax-1] = True answer[yax-1][xax-1] = cost if xax != 1: if not shortest[yax-1][xax-2]: if grid[yax-1][xax-2] == '.': heapq.heappush(hq,(cost+l,xax-1,yax)) elif grid[yax-1][xax-2] == '@': heapq.heappush(hq,(cost+l+p,xax-1,yax)) if xax != w: if not shortest[yax-1][xax]: if grid[yax-1][xax] == '.': heapq.heappush(hq,(cost+r,xax+1,yax)) elif grid[yax-1][xax] == '@': heapq.heappush(hq,(cost+r+p,xax+1,yax)) if yax != 1: if not shortest[yax-2][xax-1]: if grid[yax-2][xax-1] == '.': heapq.heappush(hq,(cost+u,xax,yax-1)) elif grid[yax-2][xax-1] == '@': heapq.heappush(hq,(cost+u+p,xax,yax-1)) if yax != h: if not shortest[yax][xax-1]: if grid[yax][xax-1] == '.': heapq.heappush(hq,(cost+d,xax,yax+1)) elif grid[yax][xax-1] == '@': heapq.heappush(hq,(cost+d+p,xax,yax+1)) if answer[gy-1][gx-1] <= k: print('Yes') else: print('No')