結果
| 問題 | No.34 砂漠の行商人 | 
| コンテスト | |
| ユーザー |  Kude | 
| 提出日時 | 2020-09-05 20:31:20 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 747 bytes | 
| コンパイル時間 | 145 ms | 
| コンパイル使用メモリ | 82,080 KB | 
| 実行使用メモリ | 469,916 KB | 
| 最終ジャッジ日時 | 2024-11-29 06:06:27 | 
| 合計ジャッジ時間 | 133,031 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 TLE * 21 | 
ソースコード
from heapq import heappush, heappop
n, v, sy, sx, gy, gx = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
l = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 18
dist = [[[INF] * 2000 for _ in range(n)] for _ in range(n)]
dist[sx][sy][0] = 0
q = [(0, sx, sy, 0)]
while q:
    d, x, y, c = heappop(q)
    if d > dist[x][y][c]:
        continue
    for dx, dy in (1, 0), (0, 1), (-1, 0), (0, -1):
        nx, ny = x + dx, y + dy
        if not (0 <= nx < n and 0 <= ny < n):
            continue
        nc = c + l[nx][ny]
        if nc < 2000 and d + 1 < dist[nx][ny][nc]:
            dist[nx][ny][nc] = d + 1
            heappush(q, (d + 1, nx, ny, nc))
ans = min(dist[gx][gy][:v])
if ans == INF:
    ans = -1
print(ans)
            
            
            
        