結果

問題 No.1638 Robot Maze
コンテスト
ユーザー flippergo
提出日時 2026-10-22 19:23:15
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 1,882 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 86 ms
コンパイル使用メモリ 64,504 KB
実行使用メモリ 63,552 KB
最終ジャッジ日時 2026-10-22 19:23:23
合計ジャッジ時間 7,656 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import heapq
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 = ["#"+input().strip() for _ in range(H)]
C = ["#"*(W+1)]+C
INFTY = 10**14
dist = [[INFTY for _ in range(W+1)] for _ in range(H+1)]
visited = [[False for _ in range(W+1)] for _ in range(H+1)]
dist[xs][ys] = 0
heap = [(0,xs,ys)]
while heap:
    d,i,j = heapq.heappop(heap)
    if dist[i][j]<d:continue
    visited[i][j] = True
    if 1<=i-1<=H and C[i-1][j]=="." and visited[i-1][j]==False:
        if dist[i-1][j]>d+U:
            dist[i-1][j] = d+U
            heapq.heappush(heap,(d+U,i-1,j))
    elif 1<=i-1<=H and C[i-1][j]=="@" and visited[i-1][j]==False:
        if dist[i-1][j]>d+U+P:
            dist[i-1][j] = d+U+P
            heapq.heappush(heap,(d+U,i-1,j))
    if 1<=i+1<=H and C[i+1][j]=="." and visited[i+1][j]==False:
        if dist[i+1][j]>d+D:
            dist[i+1][j] = d+D
            heapq.heappush(heap,(d+D,i+1,j))
    elif 1<=i+1<=H and C[i+1][j]=="@" and visited[i+1][j]==False:
        if dist[i+1][j]>d+D+P:
            dist[i+1][j] = d+D+P
            heapq.heappush(heap,(d+D+P,i+1,j))
    if 1<=j-1<=W and C[i][j-1]=="." and visited[i][j-1]==False:
        if dist[i][j-1]>d+L:
            dist[i][j-1]=d+L
            heapq.heappush(heap,(d+L,i,j-1))
    elif 1<=j-1<=W and C[i][j-1]=="@" and visited[i][j-1]==False:
        if dist[i][j-1]>d+L+P:
            dist[i][j-1]=d+L+P
            heapq.heappush(heap,(d+L+P,i,j-1))
    if 1<=j+1<=W and C[i][j+1]=="." and visited[i][j+1]==False:
        if dist[i][j+1]>d+R:
            dist[i][j+1]=d+R
            heapq.heappush(heap,(d+R,i,j+1))
    elif 1<=j+1<=W and C[i][j+1]=="@" and visited[i][j+1]==False:
        if dist[i][j+1]>d+R+P:
            dist[i][j+1]=d+R+P
            heapq.heappush(heap,(d+R+P,i,j+1))
if dist[xt][yt]<=K:
    print("Yes")
else:
    print("No")
0