結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
|
提出日時 | 2017-12-12 12:26:59 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 851 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 289,824 KB |
最終ジャッジ日時 | 2024-12-14 04:55:50 |
合計ジャッジ時間 | 13,686 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 TLE * 1 |
ソースコード
from queue import Queue def solve(): n, v, sy, sx, gy, gx = list(map(int, input().split())) if v > (abs(sx - gx) + abs(sy - gy)) * 9: return abs(sx - gx) + abs(sy - gy) gx, gy = gx - 1, gy - 1 g = [list(map(int, input().split())) for i in range(n)] dis = [[[-1] * (v + 1) for j in range(n)] for i in range(n)] dis[sx - 1][sy - 1][v] = 0; queue = Queue() queue.put((sx - 1, sy - 1, v)) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] while not queue.empty(): u = queue.get() for i in range(4): x, y = u[0] + dx[i], u[1] + dy[i] if x < 0 or x >= n or y < 0 or y >= n: continue z = u[2] - g[x][y] if z > 0 and dis[x][y][z] == -1: dis[x][y][z] = dis[u[0]][u[1]][u[2]] + 1 if x == gx and y == gy: return dis[x][y][z] queue.put((x, y, z)) return -1 print(solve())