結果
| 問題 |
No.614 壊れたキャンパス
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-05-30 12:39:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,114 bytes |
| コンパイル時間 | 379 ms |
| コンパイル使用メモリ | 82,400 KB |
| 実行使用メモリ | 146,668 KB |
| 最終ジャッジ日時 | 2024-11-08 20:44:06 |
| 合計ジャッジ時間 | 9,621 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 13 |
ソースコード
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:
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)
tktk_snsn