結果

問題 No.1638 Robot Maze
ユーザー puznekopuzneko
提出日時 2021-12-02 23:42:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 2,228 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 79,480 KB
最終ジャッジ日時 2024-07-05 02:16:59
合計ジャッジ時間 6,519 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,864 KB
testcase_01 AC 41 ms
52,696 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 108 ms
76,932 KB
testcase_04 AC 40 ms
52,864 KB
testcase_05 AC 41 ms
53,120 KB
testcase_06 AC 41 ms
53,120 KB
testcase_07 AC 42 ms
53,120 KB
testcase_08 AC 41 ms
53,376 KB
testcase_09 AC 41 ms
52,864 KB
testcase_10 AC 42 ms
52,864 KB
testcase_11 AC 42 ms
52,864 KB
testcase_12 AC 41 ms
53,120 KB
testcase_13 AC 40 ms
52,992 KB
testcase_14 AC 69 ms
71,624 KB
testcase_15 AC 96 ms
76,928 KB
testcase_16 AC 94 ms
77,040 KB
testcase_17 AC 101 ms
77,408 KB
testcase_18 AC 48 ms
61,184 KB
testcase_19 AC 97 ms
76,884 KB
testcase_20 AC 95 ms
77,064 KB
testcase_21 AC 67 ms
69,632 KB
testcase_22 AC 67 ms
69,248 KB
testcase_23 AC 67 ms
69,376 KB
testcase_24 AC 68 ms
69,760 KB
testcase_25 AC 67 ms
69,888 KB
testcase_26 AC 73 ms
73,984 KB
testcase_27 AC 72 ms
73,728 KB
testcase_28 AC 74 ms
74,368 KB
testcase_29 AC 74 ms
74,368 KB
testcase_30 AC 41 ms
52,864 KB
testcase_31 AC 42 ms
53,120 KB
testcase_32 AC 118 ms
77,756 KB
testcase_33 AC 126 ms
77,764 KB
testcase_34 AC 106 ms
77,316 KB
testcase_35 AC 161 ms
78,316 KB
testcase_36 AC 114 ms
77,560 KB
testcase_37 AC 142 ms
77,796 KB
testcase_38 AC 48 ms
60,928 KB
testcase_39 AC 145 ms
77,920 KB
testcase_40 AC 133 ms
79,092 KB
testcase_41 AC 161 ms
78,916 KB
testcase_42 AC 82 ms
74,968 KB
testcase_43 AC 182 ms
78,676 KB
testcase_44 AC 145 ms
78,480 KB
testcase_45 AC 78 ms
74,428 KB
testcase_46 AC 105 ms
77,420 KB
testcase_47 AC 154 ms
78,844 KB
testcase_48 AC 110 ms
76,920 KB
testcase_49 AC 149 ms
78,060 KB
testcase_50 AC 145 ms
79,480 KB
testcase_51 AC 132 ms
77,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from heapq import heappush, heappop

h, w = [int(x) for x in stdin.readline().rstrip().split()]
u, d, r, l, k, p = [int(x) for x in stdin.readline().rstrip().split()]
xs, ys, xt, yt = [int(x) for x in stdin.readline().rstrip().split()]
c = [stdin.readline().rstrip() for _ in range(h)]

kabe = ["#" for i in range(w+2)]
data = [kabe]
for i in range(h):
    kari = ["#"]
    for j in range(w):
        kari.append(c[i][j])
    kari.append("#")
    data.append(kari)
data.append(kabe)

hq = [(0,xs,ys)]
infty = 10**18
dist = [[infty for i in range(w+2)] for j in range(h+2)]
done = [[False for i in range(w+2)] for j in range(h+2)]
dist[xs][ys] = 0
while hq:
    cost, nowx, nowy = heappop(hq)
    if not done[nowx][nowy]:
        if (nowx == xt) & (nowy == yt):
            if cost <= k:
                print("Yes")
            else:
                print("No")
            exit()
        done[nowx][nowy] = True
        if (data[nowx-1][nowy] != "#") & (not done[nowx-1][nowy]):
            nextcost = cost + u
            if data[nowx-1][nowy] == "@":
                nextcost += p
            if (dist[nowx-1][nowy] > nextcost):
                dist[nowx-1][nowy] = nextcost
                heappush(hq, (nextcost, nowx-1, nowy))
        if (data[nowx+1][nowy] != "#") & (not done[nowx+1][nowy]):
            nextcost = cost + d
            if data[nowx+1][nowy] == "@":
                nextcost += p
            if (dist[nowx+1][nowy] > nextcost):
                dist[nowx+1][nowy] = nextcost
                heappush(hq, (nextcost, nowx+1, nowy))
        if (data[nowx][nowy-1] != "#") & (not done[nowx][nowy-1]):
            nextcost = cost + l
            if data[nowx][nowy-1] == "@":
                nextcost += p
            if (dist[nowx][nowy-1] > nextcost):
                dist[nowx][nowy-1] = nextcost
                heappush(hq, (nextcost, nowx, nowy-1))
        if (data[nowx][nowy+1] != "#") & (not done[nowx][nowy+1]):
            nextcost = cost + r
            if data[nowx][nowy+1] == "@":
                nextcost += p
            if (dist[nowx][nowy+1] > nextcost):
                dist[nowx][nowy+1] = nextcost
                heappush(hq, (nextcost, nowx, nowy+1))

print("No")
0