結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
![]() |
提出日時 | 2020-12-24 04:50:27 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 328 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 148,992 KB |
最終ジャッジ日時 | 2024-09-21 16:49:03 |
合計ジャッジ時間 | 5,027 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 RE * 8 |
ソースコード
from collections import deque import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 100000 U = 10009 DX = (-1, 0, 1, 0, -1, -1, 1, 1) DY = (0, 1, 0, -1, -1, 1, -1, 1) DX = DX[:4] DY = DY[:4] N, V, sy, sx, gy, gx = map(int, input().split()) L = tuple(tuple(map(int, input().split())) for _ in range(N)) sy -= 1 sx -= 1 gx -= 1 gy -= 1 dist = [[[inf] * 401 for _ in range(N)] for _ in range(N)] dist[sx][sy][0] = 0 que = deque([(sx, sy, 0)]) while que: x, y, now = que.popleft() if (x, y) == (gx, gy): break d = dist[x][y][now] for dx, dy in zip(DX, DY): nx = x + dx ny = y + dy if 0 <= nx < N and 0 <= ny < N: nxt = now + L[nx][ny] if nxt < V and dist[nx][ny][nxt] > d + 1: dist[nx][ny][nxt] = d + 1 que.append((nx, ny, nxt)) ans = min(dist[gx][gy]) if ans >= inf: ans = -1 print(ans)