結果
問題 | No.1638 Robot Maze |
ユーザー |
👑 ![]() |
提出日時 | 2021-08-06 21:42:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 818 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 81,996 KB |
実行使用メモリ | 77,424 KB |
最終ジャッジ日時 | 2024-09-17 01:33:44 |
合計ジャッジ時間 | 5,493 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
from heapq import heapify,heappop,heappush H,W=map(int,input().split()) U,D,R,L,K,P=map(int,input().split()) xs,ys,xt,yt=map(int,input().split()) C=["*"*(W+2)] for _ in range(H): C.append("*"+input()+"*") C.append("*"*(W+2)) inf=float("inf") DP=[[inf]*(W+2) for _ in range(H+2)]; DP[xs][ys]=0 Q=[(0,(xs,ys))] V=[((-1,0),U),((1,0),D),((0,1),R),((0,-1),L)] while Q: d,(x,y)=heappop(Q) if DP[x][y]<d: continue if x==xt and y==yt: break for (a,b),c in V: if 1<=x+a<=H and 1<=y+b<=W and C[x+a][y+b]!="#": if C[x+a][y+b]==".": m=d+c else: m=d+c+P else: continue if DP[x+a][y+b]>m: DP[x+a][y+b]=m heappush(Q,(m,(x+a,y+b))) print("Yes" if DP[xt][yt]<=K else "No")