結果

問題 No.614 壊れたキャンパス
ユーザー mkawa2mkawa2
提出日時 2023-09-09 17:51:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 1,599 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 144,656 KB
最終ジャッジ日時 2023-09-09 17:51:54
合計ジャッジ時間 8,782 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,416 KB
testcase_01 AC 89 ms
71,580 KB
testcase_02 AC 90 ms
71,416 KB
testcase_03 AC 89 ms
71,644 KB
testcase_04 AC 91 ms
71,516 KB
testcase_05 AC 90 ms
71,420 KB
testcase_06 AC 90 ms
71,220 KB
testcase_07 AC 90 ms
71,592 KB
testcase_08 AC 499 ms
89,912 KB
testcase_09 AC 650 ms
144,656 KB
testcase_10 AC 557 ms
97,492 KB
testcase_11 AC 416 ms
91,492 KB
testcase_12 AC 476 ms
91,908 KB
testcase_13 AC 427 ms
91,504 KB
testcase_14 AC 406 ms
89,372 KB
testcase_15 AC 551 ms
93,428 KB
testcase_16 AC 458 ms
90,892 KB
testcase_17 AC 511 ms
107,056 KB
testcase_18 AC 271 ms
111,712 KB
testcase_19 AC 257 ms
101,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

from collections import defaultdict

n, m, k, s, t = LI()
s, t = s-1, t-1
bc = [[] for _ in range(n)]
for _ in range(m):
    a, b, c = LI1()
    bc[a].append((b, c))

dp = defaultdict(lambda: inf)
dp[s] = 0

for i in range(n-1):
    ndp = defaultdict(lambda: inf)
    bci = bc[i]
    l = len(bci)
    bci.sort(key=lambda x: x[0])

    mn, p, ff = inf, 0, sorted(dp)
    for f in ff+[inf]:
        while p < l and bci[p][0] < f:
            b, c = bci[p]
            p += 1
            ndp[c] = min(ndp[c], mn+b)
        mn = min(mn, dp[f]-f)

    mn, p = inf, l-1
    for f in ff[::-1]+[-1]:
        while p >= 0 and bci[p][0] > f:
            b, c = bci[p]
            p -= 1
            ndp[c] = min(ndp[c], mn-b)
        mn = min(mn, dp[f]+f)

    dp = ndp

ans = inf
for f in dp:
    ans = min(ans, dp[f]+abs(t-f))
if ans == inf: ans = -1

print(ans)
0