結果
問題 | No.614 壊れたキャンパス |
ユーザー | maspy |
提出日時 | 2020-03-04 10:41:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,596 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 89,776 KB |
最終ジャッジ日時 | 2024-10-13 23:34:44 |
合計ジャッジ時間 | 11,869 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
10,752 KB |
testcase_01 | AC | 26 ms
10,624 KB |
testcase_02 | AC | 28 ms
10,752 KB |
testcase_03 | AC | 25 ms
10,880 KB |
testcase_04 | AC | 28 ms
10,752 KB |
testcase_05 | AC | 26 ms
10,752 KB |
testcase_06 | AC | 26 ms
10,752 KB |
testcase_07 | AC | 26 ms
10,752 KB |
testcase_08 | AC | 742 ms
74,012 KB |
testcase_09 | AC | 1,289 ms
89,776 KB |
testcase_10 | WA | - |
testcase_11 | AC | 746 ms
76,428 KB |
testcase_12 | AC | 864 ms
75,952 KB |
testcase_13 | AC | 753 ms
75,808 KB |
testcase_14 | AC | 751 ms
76,624 KB |
testcase_15 | WA | - |
testcase_16 | AC | 822 ms
74,148 KB |
testcase_17 | AC | 1,123 ms
76,636 KB |
testcase_18 | AC | 516 ms
70,348 KB |
testcase_19 | AC | 469 ms
68,848 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 = 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 = 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)