結果
問題 | No.1638 Robot Maze |
ユーザー |
![]() |
提出日時 | 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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 49 |
ソースコード
from sys import stdinfrom heapq import heappush, heappoph, 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**18dist = [[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] = 0while 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] = Trueif (data[nowx-1][nowy] != "#") & (not done[nowx-1][nowy]):nextcost = cost + uif data[nowx-1][nowy] == "@":nextcost += pif (dist[nowx-1][nowy] > nextcost):dist[nowx-1][nowy] = nextcostheappush(hq, (nextcost, nowx-1, nowy))if (data[nowx+1][nowy] != "#") & (not done[nowx+1][nowy]):nextcost = cost + dif data[nowx+1][nowy] == "@":nextcost += pif (dist[nowx+1][nowy] > nextcost):dist[nowx+1][nowy] = nextcostheappush(hq, (nextcost, nowx+1, nowy))if (data[nowx][nowy-1] != "#") & (not done[nowx][nowy-1]):nextcost = cost + lif data[nowx][nowy-1] == "@":nextcost += pif (dist[nowx][nowy-1] > nextcost):dist[nowx][nowy-1] = nextcostheappush(hq, (nextcost, nowx, nowy-1))if (data[nowx][nowy+1] != "#") & (not done[nowx][nowy+1]):nextcost = cost + rif data[nowx][nowy+1] == "@":nextcost += pif (dist[nowx][nowy+1] > nextcost):dist[nowx][nowy+1] = nextcostheappush(hq, (nextcost, nowx, nowy+1))print("No")