結果
問題 | No.34 砂漠の行商人 |
ユーザー | rlangevin |
提出日時 | 2023-09-19 12:18:08 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,611 bytes |
コンパイル時間 | 716 ms |
コンパイル使用メモリ | 87,196 KB |
実行使用メモリ | 667,160 KB |
最終ジャッジ日時 | 2023-09-19 12:18:21 |
合計ジャッジ時間 | 12,321 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 94 ms
71,952 KB |
testcase_01 | AC | 109 ms
76,756 KB |
testcase_02 | AC | 165 ms
78,568 KB |
testcase_03 | AC | 94 ms
71,540 KB |
testcase_04 | AC | 375 ms
126,684 KB |
testcase_05 | AC | 452 ms
136,160 KB |
testcase_06 | AC | 128 ms
78,716 KB |
testcase_07 | AC | 566 ms
169,376 KB |
testcase_08 | AC | 938 ms
227,752 KB |
testcase_09 | AC | 103 ms
77,036 KB |
testcase_10 | AC | 99 ms
76,748 KB |
testcase_11 | AC | 100 ms
76,900 KB |
testcase_12 | AC | 386 ms
125,440 KB |
testcase_13 | AC | 100 ms
76,928 KB |
testcase_14 | AC | 101 ms
76,948 KB |
testcase_15 | AC | 100 ms
76,880 KB |
testcase_16 | AC | 102 ms
76,964 KB |
testcase_17 | AC | 99 ms
76,940 KB |
testcase_18 | AC | 93 ms
71,868 KB |
testcase_19 | MLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
from collections import deque inf = 10 ** 18 def bfs(G, s, N, N2): Q = deque([]) dist = [inf] * N par = [-1] * N sz = [1] * N val = [[-1] * N2 for i in range(N2)] dist[s] = 0 for u in G[s]: par[u] = s dist[u] = 1 sz[u] += sz[s] Q.append(u) while Q: u = Q.popleft() for v in G[u]: if dist[v] != inf: continue x, y, vv = g(v) if val[x][y] > vv: continue dist[v] = dist[u] + 1 par[v] = u sz[v] += sz[u] Q.append(v) return dist N, V, sx, sy, gx, gy = map(int, input().split()) sx, sy, gx, gy = sx-1, sy-1, gx-1, gy-1 d = abs(sx - gx) + abs(sy - gy) L = [] for i in range(N): L.append(list(map(int, input().split()))) M = N * N * (V + 1) if V > d * 9: print(d) exit() def f(x, y, v): return x + y * N + v * N * N def g(n): v = n // (N * N) n %= N * N y, x = divmod(n, N) return x, y, v dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] G = [[] for i in range(M)] for i in range(N): for j in range(N): for k in range(4): x = i + dx[k] y = j + dy[k] if x < 0 or x > N - 1 or y < 0 or y > N - 1: continue for v in range(1, V + 1): if v - L[x][y] <= 0: continue G[f(i, j, v)].append(f(x, y, v - L[x][y])) D = bfs(G, f(sy, sx, V), M, N) ans = inf for v in range(1, V + 1): ans = min(ans, D[f(gy, gx, v)]) print(ans) if ans != inf else print(-1)