結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー lloyzlloyz
提出日時 2022-10-14 23:17:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,484 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 113,248 KB
最終ジャッジ日時 2023-09-08 23:38:02
合計ジャッジ時間 6,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
75,876 KB
testcase_01 AC 87 ms
71,476 KB
testcase_02 AC 85 ms
71,636 KB
testcase_03 AC 85 ms
71,492 KB
testcase_04 AC 278 ms
103,824 KB
testcase_05 AC 255 ms
95,300 KB
testcase_06 AC 133 ms
80,972 KB
testcase_07 AC 136 ms
82,524 KB
testcase_08 AC 282 ms
113,248 KB
testcase_09 AC 332 ms
102,992 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    G = [defaultdict(list), defaultdict(list)]
    for _ in range(m):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        G[0][x].append((y, max(H[y] - H[x], 0)))
        G[1][y].append((x, max(H[x] - H[y], 0)))

    DP = [[[-1, -1] for _ in range(n)] for _ in range(2)]
    DP[0][0][0] = 0
    DP[1][n - 1][0] = 0
    H = [(0, 0), (0, n - 1 + 2 * n)]
    heapify(H)
    while H:
        cnt, cp = heappop(H)
        cnt *= -1
        if cp >= 2 * n:
            cp -= 2 * n
            idx = 1
        else:
            idx = 0
        if cp >= n:
            cp -= n
            up = 1
        else:
            up = 0
        if cnt < DP[idx][cp][up]:
            continue
        for np, d in G[idx][cp]:
            if d > 0:
                if up == 0:
                    res = cnt + d
                    if res <= DP[idx][np][1]:
                        continue
                    DP[idx][np][1] = res
                    heappush(H, (-res, np + n + idx * 2 * n))
            else:
                if cnt <= DP[idx][np][0]:
                    continue
                DP[idx][np][0] = cnt
                heappush(H, (-cnt, np + idx * 2 * n))
    print(max(DP[0][n - 1]))
    print(max(DP[1][0]))

if __name__ == '__main__':
    main()
0