結果

問題 No.614 壊れたキャンパス
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-30 12:40:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,117 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 146,660 KB
最終ジャッジ日時 2024-04-26 07:43:00
合計ジャッジ時間 8,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,888 KB
testcase_01 WA -
testcase_02 AC 41 ms
54,016 KB
testcase_03 AC 40 ms
54,016 KB
testcase_04 AC 40 ms
54,016 KB
testcase_05 AC 40 ms
54,400 KB
testcase_06 WA -
testcase_07 AC 40 ms
54,016 KB
testcase_08 WA -
testcase_09 AC 1,434 ms
146,660 KB
testcase_10 AC 248 ms
104,284 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 207 ms
95,744 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 320 ms
132,096 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0