結果
問題 | No.34 砂漠の行商人 |
ユーザー | brthyyjp |
提出日時 | 2021-11-03 02:53:15 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 855 bytes |
コンパイル時間 | 140 ms |
コンパイル使用メモリ | 82,576 KB |
実行使用メモリ | 193,660 KB |
最終ジャッジ日時 | 2024-04-20 15:22:06 |
合計ジャッジ時間 | 13,180 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,044 KB |
testcase_01 | AC | 35 ms
52,884 KB |
testcase_02 | AC | 88 ms
76,412 KB |
testcase_03 | AC | 41 ms
53,384 KB |
testcase_04 | AC | 273 ms
79,180 KB |
testcase_05 | AC | 253 ms
78,584 KB |
testcase_06 | AC | 83 ms
76,760 KB |
testcase_07 | AC | 421 ms
80,752 KB |
testcase_08 | AC | 568 ms
84,252 KB |
testcase_09 | AC | 2,927 ms
193,660 KB |
testcase_10 | AC | 380 ms
82,304 KB |
testcase_11 | AC | 1,095 ms
94,208 KB |
testcase_12 | AC | 159 ms
77,804 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, v, sx, sy, gx, gy = map(int, input().split()) sx, sy = sx-1, sy-1 gx, gy = gx-1, gy-1 L = [] for i in range(n): l = list(map(int, input().split())) L += l s = sy*n+sx g = gy*n+gx import heapq hq = [(0, v, s)] HP = [0]*(n*n) HP[s] = v heapq.heapify(hq) visit = [False]*(n*n) while hq: time, hp, i = heapq.heappop(hq) y, x = divmod(i, n) if i == g: print(time) exit() for dy, dx in (-1, 0), (1, 0), (0, 1), (0, -1): ny, nx = y+dy, x+dx if 0 <= ny < n and 0 <= nx < n: j = ny*n+nx if hp-L[j] <= 0: continue if hp-L[j] > HP[j]: HP[j] = hp-L[j] heapq.heappush(hq, (time+1, hp-L[j], j)) print(-1)