結果
| 問題 |
No.1638 Robot Maze
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 22:56:49 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,607 bytes |
| コンパイル時間 | 95 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 18,716 KB |
| 最終ジャッジ日時 | 2024-09-17 03:08:17 |
| 合計ジャッジ時間 | 3,709 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 48 |
ソースコード
import sys
sys.setrecursionlimit(10**6) # 再帰関数使う時有効
H, W = map(int, input().split())
U, D, R, L, K, P = map(int, input().split())
x, y, xt, yt = map(int, input().split())
start = [x-1, y-1]
goal = [xt-1, yt-1]
allow = [[1, 0], [0, 1], [-1, 0], [0, -1]]
allow_cost = [D, R, U, L]
C = [input() for i in range(H)]
# def fps(now, cost):
# if now == goal:
# return cost
# ans = 10**13+8
# for i in range(4):
# nextx = now[0]+allow[i][0]
# nexty = now[1]+allow[i][1]
# if not (0 <= nextx < H and 0 <= nexty < W):
# continue
# if C[nextx][nexty] == '.':
# new_cost = cost+allow_cost[i]
# elif C[nextx][nexty] == '@':
# new_cost = cost+allow_cost[i]+P
# else:
# continue
# ans = min(ans, fps([nextx, nexty], new_cost))
# return ans
dp = [[-1]*W for i in range(H)]
dp[start[0]][start[1]] = 0
q = [start]
while q:
now = q.pop()
for i in range(4):
nextx = now[0]+allow[i][0]
nexty = now[1]+allow[i][1]
if not (0 <= nextx < H and 0 <= nexty < W):
continue
if C[nextx][nexty] == '.':
new_cost = dp[now[0]][now[1]]+allow_cost[i]
elif C[nextx][nexty] == '@':
new_cost = dp[now[0]][now[1]]+allow_cost[i]+P
else:
continue
if dp[nextx][nexty] == -1 or dp[nextx][nexty] > new_cost:
dp[nextx][nexty] = new_cost
q.append([nextx, nexty])
if dp[goal[0]][goal[1]] <= K and dp[goal[0]][goal[1]] != -1:
print('Yes')
else:
print('No')