結果
問題 | No.614 壊れたキャンパス |
ユーザー | maspy |
提出日時 | 2020-03-04 10:41:59 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,430 ms / 2,000 ms |
コード長 | 1,604 bytes |
コンパイル時間 | 80 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 89,772 KB |
最終ジャッジ日時 | 2024-10-13 23:35:10 |
合計ジャッジ時間 | 11,918 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,752 KB |
testcase_01 | AC | 27 ms
10,624 KB |
testcase_02 | AC | 26 ms
10,752 KB |
testcase_03 | AC | 27 ms
10,752 KB |
testcase_04 | AC | 27 ms
10,880 KB |
testcase_05 | AC | 28 ms
10,752 KB |
testcase_06 | AC | 27 ms
10,752 KB |
testcase_07 | AC | 27 ms
10,624 KB |
testcase_08 | AC | 795 ms
73,884 KB |
testcase_09 | AC | 1,430 ms
89,772 KB |
testcase_10 | AC | 1,234 ms
76,768 KB |
testcase_11 | AC | 787 ms
76,308 KB |
testcase_12 | AC | 808 ms
75,952 KB |
testcase_13 | AC | 761 ms
75,820 KB |
testcase_14 | AC | 768 ms
76,500 KB |
testcase_15 | AC | 938 ms
74,020 KB |
testcase_16 | AC | 853 ms
74,020 KB |
testcase_17 | AC | 1,152 ms
76,632 KB |
testcase_18 | AC | 532 ms
70,352 KB |
testcase_19 | AC | 476 ms
69,008 KB |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import defaultdict INF = 10 ** 18 # %% N, M, _, S, T = map(int, readline().split()) if M == 0: if N == 1: print(abs(S - T)) else: print(-1) exit() m = map(int, read().split()) A, B, C = zip(*zip(m, m, m)) # %% A_to_BC = [[] for _ in range(N + 1)] for a, b, c in zip(A, B, C): A_to_BC[a].append((b, c)) # %% A_to_BC[N].append((T, T)) # %% def to_next_building(a, before): event = [(b, c) for b, c in A_to_BC[a]] event += [(key, -value) for key, value in before.items() if value != INF] event += [(-INF, -INF), (INF, -INF)] event.sort() after = defaultdict(lambda: INF) min_const_term = 3 * INF for n, x in event: if x > 0: newcost = n + min_const_term if after[x] > newcost: after[x] = newcost else: const_term = -n - x if min_const_term > const_term: min_const_term = const_term min_const_term = 3 * INF for n, x in event[::-1]: if x > 0: newcost = -n + min_const_term if after[x] > newcost: after[x] = newcost else: const_term = n - x if min_const_term > const_term: min_const_term = const_term return after # %% dist = defaultdict(int) dist[S] = 0 for a in range(1, N + 1): dist = to_next_building(a, dist) answer = dist[T] if dist[T] < INF else -1 print(answer)