結果
問題 |
No.614 壊れたキャンパス
|
ユーザー |
![]() |
提出日時 | 2021-05-30 12:40:33 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,117 bytes |
コンパイル時間 | 632 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 146,656 KB |
最終ジャッジ日時 | 2024-11-08 20:44:18 |
合計ジャッジ時間 | 9,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 WA * 10 |
ソースコード
from collections import defaultdict import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**18 N, M, K, S, T = map(int, input().split()) if N == 1: print(abs(S - T)) exit() stair = [[] for _ in range(N+1)] stair[1].append((S, ~S)) ok = [0] * N for _ in range(M): a, b, c = map(int, input().split()) ok[a] = 1 stair[a].append((b, 1)) stair[a+1].append((c, ~b)) dp = defaultdict(lambda: inf) dp[S] = 0 for i in range(1, N): if not ok[i]: print(-1) exit() ndp = defaultdict(lambda: inf) stair[i].sort(key=lambda x: (x[0], x[1])) vmin = inf for s, f in stair[i]: if f >= 0: ndp[s] = min(ndp[s], s + vmin) else: f = ~f vmin = min(vmin, dp[f] - s) vmin = inf stair[i].sort(key=lambda x: (x[0], -x[1])) for s, f in stair[i][::-1]: if f >= 0: ndp[s] = min(ndp[s], s + vmin) else: f = ~f vmin = min(vmin, dp[f] + s) dp = ndp ans = inf for s, f in stair[N]: ans = min(ans, abs(T - s) + dp[~f]) print(ans)