結果

問題 No.1638 Robot Maze
ユーザー ygd.ygd.
提出日時 2021-08-06 21:46:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 77,268 KB
最終ジャッジ日時 2023-10-17 03:05:16
合計ジャッジ時間 5,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,268 KB
testcase_01 AC 39 ms
53,268 KB
testcase_02 AC 39 ms
53,268 KB
testcase_03 AC 85 ms
75,820 KB
testcase_04 AC 41 ms
53,420 KB
testcase_05 AC 40 ms
53,420 KB
testcase_06 AC 40 ms
53,420 KB
testcase_07 AC 40 ms
53,420 KB
testcase_08 AC 41 ms
53,420 KB
testcase_09 AC 40 ms
53,420 KB
testcase_10 AC 40 ms
53,420 KB
testcase_11 AC 40 ms
53,420 KB
testcase_12 AC 40 ms
53,420 KB
testcase_13 AC 40 ms
53,420 KB
testcase_14 AC 91 ms
76,116 KB
testcase_15 AC 74 ms
72,532 KB
testcase_16 AC 74 ms
72,532 KB
testcase_17 AC 85 ms
76,120 KB
testcase_18 AC 41 ms
53,420 KB
testcase_19 AC 74 ms
72,536 KB
testcase_20 AC 73 ms
72,536 KB
testcase_21 AC 54 ms
66,116 KB
testcase_22 AC 54 ms
66,116 KB
testcase_23 AC 54 ms
66,116 KB
testcase_24 AC 54 ms
66,116 KB
testcase_25 AC 54 ms
66,116 KB
testcase_26 AC 61 ms
70,392 KB
testcase_27 AC 60 ms
70,392 KB
testcase_28 AC 61 ms
70,392 KB
testcase_29 AC 60 ms
70,392 KB
testcase_30 AC 39 ms
53,420 KB
testcase_31 AC 40 ms
53,420 KB
testcase_32 AC 100 ms
75,932 KB
testcase_33 AC 122 ms
76,216 KB
testcase_34 AC 104 ms
76,116 KB
testcase_35 AC 121 ms
76,120 KB
testcase_36 AC 121 ms
76,248 KB
testcase_37 AC 98 ms
76,116 KB
testcase_38 AC 107 ms
76,116 KB
testcase_39 AC 110 ms
76,232 KB
testcase_40 AC 122 ms
76,128 KB
testcase_41 AC 111 ms
76,124 KB
testcase_42 AC 123 ms
76,220 KB
testcase_43 AC 139 ms
76,560 KB
testcase_44 AC 142 ms
77,268 KB
testcase_45 AC 146 ms
77,000 KB
testcase_46 AC 112 ms
76,120 KB
testcase_47 AC 110 ms
76,196 KB
testcase_48 AC 121 ms
76,188 KB
testcase_49 AC 101 ms
76,116 KB
testcase_50 AC 121 ms
76,124 KB
testcase_51 AC 147 ms
77,004 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush

def main():
    H,W = map(int,input().split())
    U,D,R,L,K,P = map(int,input().split())
    xs,ys,xt,yt = map(int,input().split())
    xs -= 1; ys -= 1; xt -= 1; yt -= 1
    C = [str(input()) for _ in range(H)]

    INF = pow(10,20)
    #S:start, V: node, E: Edge, G: Graph
    d = [[INF]*W for _ in range(H)]
    d[xs][ys] = 0
    PQ = []
    heappush(PQ,(0,xs,ys))

    dxdy = [(-1,0),(1,0),(0,1),(0,-1)] #U,D,R,L
    Pay = [U,D,R,L]

    while PQ:
        c,vx,vy = heappop(PQ)
        if d[vx][vy] < c:
            continue
        d[vx][vy] = c
        for i in range(4):
            ux = vx + dxdy[i][0]
            uy = vy + dxdy[i][1]
            if ux < 0 or ux >= H or uy < 0 or uy >= W: continue
            if C[ux][uy] == "#": continue #壁
            cost = Pay[i]
            if C[ux][uy] == "@": #壊す
                cost += P
            if d[ux][uy] <= cost + d[vx][vy]:
                continue
            d[ux][uy] = cost + d[vx][vy]
            heappush(PQ,(d[ux][uy],ux,uy))
    #print(d)
    if d[xt][yt] > K:
        print("No")
    else:
        print('Yes')
if __name__ == '__main__':
    main()
0