結果
問題 | No.34 砂漠の行商人 |
ユーザー | tktk_snsn |
提出日時 | 2020-12-24 04:48:01 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 923 bytes |
コンパイル時間 | 719 ms |
コンパイル使用メモリ | 11,880 KB |
実行使用メモリ | 119,044 KB |
最終ジャッジ日時 | 2023-10-21 15:34:42 |
合計ジャッジ時間 | 11,708 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 25 ms
10,312 KB |
testcase_01 | AC | 25 ms
10,416 KB |
testcase_02 | AC | 67 ms
17,136 KB |
testcase_03 | AC | 37 ms
15,832 KB |
testcase_04 | AC | 717 ms
49,924 KB |
testcase_05 | AC | 741 ms
63,452 KB |
testcase_06 | AC | 132 ms
40,592 KB |
testcase_07 | AC | 1,213 ms
89,844 KB |
testcase_08 | AC | 1,647 ms
119,044 KB |
testcase_09 | TLE | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
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] * 2000 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)