結果
問題 | No.34 砂漠の行商人 |
ユーザー | Kude |
提出日時 | 2020-09-05 20:42:08 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 885 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 87,256 KB |
実行使用メモリ | 102,628 KB |
最終ジャッジ日時 | 2023-08-19 13:04:18 |
合計ジャッジ時間 | 11,893 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
71,472 KB |
testcase_01 | AC | 81 ms
75,716 KB |
testcase_02 | AC | 130 ms
77,852 KB |
testcase_03 | AC | 74 ms
71,320 KB |
testcase_04 | AC | 477 ms
86,428 KB |
testcase_05 | AC | 483 ms
88,276 KB |
testcase_06 | AC | 132 ms
78,632 KB |
testcase_07 | AC | 700 ms
93,088 KB |
testcase_08 | AC | 943 ms
102,628 KB |
testcase_09 | AC | 77 ms
76,072 KB |
testcase_10 | AC | 78 ms
75,852 KB |
testcase_11 | AC | 78 ms
75,816 KB |
testcase_12 | AC | 502 ms
89,024 KB |
testcase_13 | AC | 81 ms
75,736 KB |
testcase_14 | AC | 79 ms
75,804 KB |
testcase_15 | AC | 80 ms
75,764 KB |
testcase_16 | AC | 78 ms
75,968 KB |
testcase_17 | AC | 79 ms
75,756 KB |
testcase_18 | AC | 76 ms
71,512 KB |
testcase_19 | TLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
from heapq import heappush, heappop n, v, sy, sx, gy, gx = map(int, input().split()) l = [list(map(int, input().split())) for _ in range(n)] sx -= 1 sy -= 1 gx -= 1 gy -= 1 shortest_dist = abs(sx - gx) + abs(sy - gy) if v > shortest_dist * 9: print(shortest_dist) exit(0) INF = 10 ** 4 dist = [[[INF for _ in range(v + 1)] for _ in range(n)] for _ in range(n)] dist[sx][sy][v] = 0 q = [(0, sx, sy, v)] while q: d, x, y, vit = heappop(q) if d > dist[x][y][vit]: 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 nvit = vit - l[nx][ny] nd = d + 1 if nvit > 0 and nd< dist[nx][ny][nvit]: dist[nx][ny][nvit] = nd heappush(q, (nd, nx, ny, nvit)) ans = min(dist[gx][gy]) if ans == INF: ans = -1 print(ans)