結果

問題 No.1638 Robot Maze
ユーザー defilementdefilement
提出日時 2021-08-06 22:06:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 75 ms
コンパイル使用メモリ 12,144 KB
実行使用メモリ 10,996 KB
最終ジャッジ日時 2023-10-17 03:29:30
合計ジャッジ時間 3,527 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,336 KB
testcase_01 AC 25 ms
10,336 KB
testcase_02 AC 27 ms
10,336 KB
testcase_03 AC 59 ms
10,884 KB
testcase_04 AC 26 ms
10,344 KB
testcase_05 AC 26 ms
10,344 KB
testcase_06 AC 26 ms
10,344 KB
testcase_07 AC 25 ms
10,344 KB
testcase_08 AC 26 ms
10,344 KB
testcase_09 AC 26 ms
10,344 KB
testcase_10 AC 26 ms
10,344 KB
testcase_11 AC 27 ms
10,344 KB
testcase_12 AC 26 ms
10,344 KB
testcase_13 AC 25 ms
10,344 KB
testcase_14 AC 40 ms
10,740 KB
testcase_15 AC 37 ms
10,648 KB
testcase_16 AC 36 ms
10,648 KB
testcase_17 AC 34 ms
10,648 KB
testcase_18 AC 27 ms
10,560 KB
testcase_19 AC 36 ms
10,644 KB
testcase_20 AC 35 ms
10,644 KB
testcase_21 AC 36 ms
10,752 KB
testcase_22 AC 35 ms
10,716 KB
testcase_23 AC 36 ms
10,716 KB
testcase_24 AC 37 ms
10,752 KB
testcase_25 AC 37 ms
10,752 KB
testcase_26 AC 36 ms
10,716 KB
testcase_27 AC 36 ms
10,716 KB
testcase_28 AC 35 ms
10,716 KB
testcase_29 AC 36 ms
10,716 KB
testcase_30 AC 24 ms
10,336 KB
testcase_31 AC 25 ms
10,336 KB
testcase_32 AC 44 ms
10,816 KB
testcase_33 AC 50 ms
10,944 KB
testcase_34 AC 55 ms
10,860 KB
testcase_35 AC 50 ms
10,996 KB
testcase_36 AC 56 ms
10,868 KB
testcase_37 AC 48 ms
10,812 KB
testcase_38 AC 49 ms
10,788 KB
testcase_39 AC 55 ms
10,860 KB
testcase_40 AC 49 ms
10,852 KB
testcase_41 AC 52 ms
10,940 KB
testcase_42 AC 52 ms
10,896 KB
testcase_43 AC 52 ms
10,828 KB
testcase_44 AC 51 ms
10,820 KB
testcase_45 AC 47 ms
10,816 KB
testcase_46 AC 51 ms
10,840 KB
testcase_47 AC 46 ms
10,808 KB
testcase_48 AC 53 ms
10,868 KB
testcase_49 AC 45 ms
10,796 KB
testcase_50 AC 51 ms
10,948 KB
testcase_51 AC 51 ms
10,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


    
0