結果

問題 No.1638 Robot Maze
ユーザー とりゐとりゐ
提出日時 2021-08-06 22:12:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 77,136 KB
最終ジャッジ日時 2023-10-17 03:35:50
合計ジャッジ時間 5,895 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,468 KB
testcase_01 AC 39 ms
53,468 KB
testcase_02 AC 38 ms
53,468 KB
testcase_03 AC 86 ms
76,068 KB
testcase_04 AC 40 ms
53,468 KB
testcase_05 AC 39 ms
53,468 KB
testcase_06 AC 39 ms
53,468 KB
testcase_07 AC 39 ms
53,468 KB
testcase_08 AC 39 ms
53,468 KB
testcase_09 AC 39 ms
53,468 KB
testcase_10 AC 40 ms
53,468 KB
testcase_11 AC 40 ms
53,468 KB
testcase_12 AC 40 ms
53,468 KB
testcase_13 AC 40 ms
53,468 KB
testcase_14 AC 102 ms
76,104 KB
testcase_15 AC 77 ms
73,952 KB
testcase_16 AC 77 ms
73,952 KB
testcase_17 AC 91 ms
76,068 KB
testcase_18 AC 43 ms
53,468 KB
testcase_19 AC 78 ms
73,816 KB
testcase_20 AC 77 ms
73,816 KB
testcase_21 AC 52 ms
63,920 KB
testcase_22 AC 53 ms
63,920 KB
testcase_23 AC 53 ms
63,920 KB
testcase_24 AC 52 ms
63,920 KB
testcase_25 AC 53 ms
63,920 KB
testcase_26 AC 59 ms
68,284 KB
testcase_27 AC 59 ms
68,284 KB
testcase_28 AC 59 ms
68,284 KB
testcase_29 AC 58 ms
68,284 KB
testcase_30 AC 38 ms
53,468 KB
testcase_31 AC 39 ms
53,468 KB
testcase_32 AC 105 ms
76,080 KB
testcase_33 AC 118 ms
76,228 KB
testcase_34 AC 118 ms
76,228 KB
testcase_35 AC 116 ms
76,184 KB
testcase_36 AC 117 ms
76,120 KB
testcase_37 AC 109 ms
76,092 KB
testcase_38 AC 112 ms
76,204 KB
testcase_39 AC 118 ms
76,156 KB
testcase_40 AC 119 ms
76,236 KB
testcase_41 AC 122 ms
76,396 KB
testcase_42 AC 118 ms
76,256 KB
testcase_43 AC 138 ms
76,940 KB
testcase_44 AC 138 ms
77,136 KB
testcase_45 AC 138 ms
76,892 KB
testcase_46 AC 127 ms
76,212 KB
testcase_47 AC 117 ms
76,144 KB
testcase_48 AC 115 ms
76,248 KB
testcase_49 AC 108 ms
76,332 KB
testcase_50 AC 118 ms
76,260 KB
testcase_51 AC 127 ms
76,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0