結果
| 問題 |
No.34 砂漠の行商人
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-07 17:39:48 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,264 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 468,468 KB |
| 最終ジャッジ日時 | 2024-07-06 23:00:27 |
| 合計ジャッジ時間 | 16,764 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 TLE * 2 -- * 12 |
ソースコード
#!/usr/bin/env python3
import sys
from collections import deque
MOD = 998244353
input = sys.stdin.readline
powerMax = 99 * 2 * 9
INF = 10 ** 16
def main():
N, V, Sx, Sy, Gx, Gy = map(int, input().split())
power_init = min(V, powerMax)
G = [list(map(int, input().split())) for _ in range(N)]
startY = Sy - 1
startX = Sx - 1
goalY = Gy - 1
goalX = Gx - 1
q = deque()
dist = [[[INF] * (powerMax + 1) for _ in range(N)] for _ in range(N)]
q.append((0, startY, startX, power_init))
dist[startY][startX][power_init] = 0
while q:
min_cost, nowY, nowX, now_power = q.popleft()
if nowY == goalY and nowX == goalX:
print(min_cost)
return
for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
nexty = nowY + dy
nextx = nowX + dx
if nexty < 0 or nextx < 0 or nexty >= N or nextx >= N:
continue
next_power = now_power - G[nexty][nextx]
if next_power <= 0 or dist[nexty][nextx][next_power] != INF:
continue
q.append((min_cost + 1, nexty, nextx, next_power))
dist[nexty][nextx][next_power] = min_cost + 1
print(-1)
return
if __name__ == '__main__':
main()