結果
問題 | No.614 壊れたキャンパス |
ユーザー | LyricalMaestro |
提出日時 | 2024-02-08 22:12:17 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,222 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 82,636 KB |
実行使用メモリ | 435,744 KB |
最終ジャッジ日時 | 2024-09-28 12:53:48 |
合計ジャッジ時間 | 27,460 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,384 KB |
testcase_01 | AC | 36 ms
52,948 KB |
testcase_02 | AC | 37 ms
53,724 KB |
testcase_03 | AC | 37 ms
53,276 KB |
testcase_04 | AC | 37 ms
54,232 KB |
testcase_05 | AC | 37 ms
53,352 KB |
testcase_06 | AC | 37 ms
54,668 KB |
testcase_07 | AC | 36 ms
52,996 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | AC | 895 ms
279,036 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | AC | 865 ms
259,112 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 1,390 ms
435,744 KB |
testcase_18 | TLE | - |
testcase_19 | AC | 1,405 ms
410,568 KB |
ソースコード
## https://yukicoder.me/problems/no/614 import heapq def main(): N, M, K, S, T = map(int, input().split()) abc = [] for _ in range(M): a, b, c = map(int, input().split()) abc.append((a - 1, b, c)) map_array = [[] for _ in range(N)] for a, b, c in abc: map_array[a].append(b) map_array[a + 1].append(c) map_array[0].append(S) map_array[-1].append(T) coord_map_array = [{} for _ in range(N)] for i, values in enumerate(map_array): values.sort() for j, value in enumerate(values): coord_map_array[i][value] = j # グラフ構築 next_nodes = [{} for _ in range(N)] for a, b, c in abc: b_i = coord_map_array[a][b] c_i = coord_map_array[a + 1][c] if b_i not in next_nodes[a]: next_nodes[a][b_i] = [] next_nodes[a][b_i].append((a + 1, c_i, 0)) for i, values in enumerate(map_array): if len(values) == 0: continue for j in range(len(values) - 1): a = values[j] b = values[j + 1] if j not in next_nodes[i]: next_nodes[i][j] = [] if (j + 1) not in next_nodes[i]: next_nodes[i][j + 1] = [] next_nodes[i][j].append((i, j + 1, b - a)) next_nodes[i][j + 1].append((i, j, b - a)) # ダイクストラ法で解く s_ = coord_map_array[0][S] t_ = coord_map_array[-1][T] fix = {} seen = {(0, s_):0} queue = [] heapq.heappush(queue, (0, 0, s_)) while len(queue) > 0: cost, a, k = heapq.heappop(queue) if (a, k) in fix: continue fix[(a, k)] = cost if k not in next_nodes[a]: continue for b, c, d in next_nodes[a][k]: if (b, c) in fix: continue new_cost = cost + d if (b, c) not in seen or seen[(b, c)] > new_cost: seen[(b, c)] = new_cost heapq.heappush(queue, (new_cost, b, c)) if (N - 1, t_) not in fix: print(-1) else: print(fix[(N -1 , t_)]) if __name__ == "__main__": main()