結果
問題 | No.614 壊れたキャンパス |
ユーザー | maspy |
提出日時 | 2020-03-04 10:36:54 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,580 bytes |
コンパイル時間 | 78 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 89,512 KB |
最終ジャッジ日時 | 2024-10-13 23:34:30 |
合計ジャッジ時間 | 13,103 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,752 KB |
testcase_01 | AC | 26 ms
10,880 KB |
testcase_02 | AC | 26 ms
10,624 KB |
testcase_03 | AC | 26 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 29 ms
10,880 KB |
testcase_06 | AC | 27 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 745 ms
73,752 KB |
testcase_09 | AC | 1,376 ms
89,512 KB |
testcase_10 | WA | - |
testcase_11 | AC | 755 ms
76,300 KB |
testcase_12 | AC | 774 ms
75,948 KB |
testcase_13 | AC | 757 ms
75,824 KB |
testcase_14 | AC | 750 ms
76,636 KB |
testcase_15 | WA | - |
testcase_16 | AC | 829 ms
74,152 KB |
testcase_17 | AC | 1,125 ms
76,760 KB |
testcase_18 | AC | 526 ms
70,220 KB |
testcase_19 | AC | 475 ms
68,960 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()] 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)