結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,192 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 39 ms
54,092 KB
testcase_04 AC 39 ms
54,004 KB
testcase_05 AC 39 ms
54,944 KB
testcase_06 WA -
testcase_07 AC 42 ms
54,404 KB
testcase_08 WA -
testcase_09 AC 1,446 ms
146,920 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 304 ms
132,224 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:
        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