結果
問題 | No.34 砂漠の行商人 |
ユーザー | katk |
提出日時 | 2016-09-03 22:28:43 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 223 ms / 5,000 ms |
コード長 | 1,455 bytes |
コンパイル時間 | 972 ms |
コンパイル使用メモリ | 11,080 KB |
実行使用メモリ | 9,644 KB |
最終ジャッジ日時 | 2023-09-10 19:25:28 |
合計ジャッジ時間 | 3,494 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
9,176 KB |
testcase_01 | AC | 24 ms
9,016 KB |
testcase_02 | AC | 28 ms
9,052 KB |
testcase_03 | AC | 24 ms
9,048 KB |
testcase_04 | AC | 51 ms
9,224 KB |
testcase_05 | AC | 58 ms
9,148 KB |
testcase_06 | AC | 45 ms
9,084 KB |
testcase_07 | AC | 104 ms
9,364 KB |
testcase_08 | AC | 119 ms
9,368 KB |
testcase_09 | AC | 93 ms
9,252 KB |
testcase_10 | AC | 48 ms
9,488 KB |
testcase_11 | AC | 70 ms
9,644 KB |
testcase_12 | AC | 33 ms
9,088 KB |
testcase_13 | AC | 223 ms
9,644 KB |
testcase_14 | AC | 220 ms
9,488 KB |
testcase_15 | AC | 27 ms
9,292 KB |
testcase_16 | AC | 45 ms
9,104 KB |
testcase_17 | AC | 27 ms
9,168 KB |
testcase_18 | AC | 27 ms
9,048 KB |
testcase_19 | AC | 102 ms
9,492 KB |
testcase_20 | AC | 150 ms
9,344 KB |
testcase_21 | AC | 30 ms
9,328 KB |
testcase_22 | AC | 32 ms
9,284 KB |
testcase_23 | AC | 28 ms
9,124 KB |
testcase_24 | AC | 171 ms
9,544 KB |
testcase_25 | AC | 44 ms
9,228 KB |
ソースコード
import queue from collections import namedtuple dx = (1, 0, -1, 0) dy = (0, -1, 0, 1) Point = namedtuple('Point', 'x y') def solve(): n, v, sx, sy, gx, gy = [int(i) for i in input().split(' ')] start = Point(x = sx-1, y = sy-1) goal = Point(x = gx-1, y = gy-1) costs = [[int(i) for i in input().split(' ')] for _ in range(n)] mincosts = [[v for _ in range(n)] for _ in range(n)] mincosts[start.y][start.x] = 0 q = queue.Queue() in_queue = [[False for _ in range(n)] for _ in range(n)] q.put(start) in_queue[start.y][start.x] = True cnt = 0 while True: tmp = queue.Queue() if q.empty() or mincosts[goal.y][goal.x] < v: break while not q.empty(): x, y = q.get() in_queue[y][x] = False for tx, ty in zip(dx, dy): nx = x + tx ny = y + ty if nx >= 0 and nx < n and ny >= 0 and ny < n: tmpcost = mincosts[y][x] + costs[ny][nx] if mincosts[ny][nx] > tmpcost: mincosts[ny][nx] = tmpcost if not in_queue[ny][nx]: tmp.put(Point(nx, ny)) in_queue[ny][nx] = True q = tmp cnt += 1 if mincosts[goal.y][goal.x] < v: print(cnt) else: print(-1) if __name__ == "__main__": solve()