結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2021-08-06 22:12:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 141 ms / 2,000 ms |
| コード長 | 1,152 bytes |
| コンパイル時間 | 150 ms |
| コンパイル使用メモリ | 82,572 KB |
| 実行使用メモリ | 77,616 KB |
| 最終ジャッジ日時 | 2024-09-17 02:14:11 |
| 合計ジャッジ時間 | 5,791 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
h,w=map(int,input().split())
u,d,r,l,k,p=map(int,input().split())
sx,sy,gx,gy=map(int,input().split())
c=[]
for i in range(h):
c.append(input())
dxdy=[(-1,0,u),(1,0,d),(0,1,r),(0,-1,l)]
#ダイクストラ法
from heapq import heappush, heappop
INF=10**18
def dijkstra(sx,sy,h,w):
dist = [[INF]*w for i in range(h)]
hq=[(0,sx-1,sy-1)] # (distance, node)
dist[sx-1][sy-1]=0
seen=[[False]*w for i in range(h)]
while hq:
a,x,y=heappop(hq) # ノードを pop する
# 変更箇所
if seen[x][y]:
continue
seen[x][y]=True
for dx,dy,cost in dxdy:
if 0<=x+dx<h and 0<=y+dy<w and seen[x+dx][y+dy]==False and c[x+dx][y+dy]!='#':
if c[x+dx][y+dy]=='.' and dist[x][y]+cost<dist[x+dx][y+dy]:
dist[x+dx][y+dy]=dist[x][y]+cost
heappush(hq,(dist[x+dx][y+dy],x+dx,y+dy))
elif c[x+dx][y+dy]=='@' and dist[x][y]+cost+p<dist[x+dx][y+dy]:
dist[x+dx][y+dy]=dist[x][y]+cost+p
heappush(hq,(dist[x+dx][y+dy],x+dx,y+dy))
return dist
t=dijkstra(sx,sy,h,w)[gx-1][gy-1]
if t<=k:
print('Yes')
else:
print('No')
とりゐ