結果
問題 | No.2100 [Cherry Alpha C] Two-way Steps |
ユーザー |
|
提出日時 | 2022-10-14 23:07:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,267 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 108,012 KB |
最終ジャッジ日時 | 2024-06-26 16:59:39 |
合計ジャッジ時間 | 6,109 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 TLE * 1 -- * 37 |
ソースコード
from collections import defaultdictfrom heapq import heapify, heappop, heappushimport sysinput = sys.stdin.readlinedef 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 -= 1y -= 1G[0][x].append((y, H[y] - H[x]))G[1][y].append((x, H[x] - H[y]))DP = [[[-1, -1] for _ in range(n)] for _ in range(2)]DP[0][0][0] = 0DP[1][n - 1][0] = 0H = [(0, 0, 0, 0), (0, n - 1, 0, 1)]heapify(H)while H:cnt, cp, up, idx = heappop(H)cnt *= -1if cnt < DP[idx][cp][up]:continuefor np, d in G[idx][cp]:if d > 0:if up == 0:if cnt + d <= DP[idx][np][1]:continueDP[idx][np][1] = cnt + dheappush(H, (-DP[idx][np][1], np, 1, idx))else:if cnt <= DP[idx][np][0]:continueDP[idx][np][0] = cntheappush(H, (-DP[idx][np][0], np, 0, idx))print(max(DP[0][n - 1]))print(max(DP[1][0]))if __name__ == '__main__':main()