結果
| 問題 | No.2100 [Cherry Alpha C] Two-way Steps |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-14 23:10:34 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,271 bytes |
| 記録 | |
| コンパイル時間 | 227 ms |
| コンパイル使用メモリ | 85,760 KB |
| 実行使用メモリ | 207,924 KB |
| 最終ジャッジ日時 | 2026-03-13 10:18:04 |
| 合計ジャッジ時間 | 38,686 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 39 TLE * 9 |
ソースコード
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, 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] = 0
DP[1][n - 1][0] = 0
H = [(0, 0, 0, 0), (0, n - 1, 0, 1)]
heapify(H)
while H:
cnt, cp, up, idx = heappop(H)
cnt *= -1
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, 1, idx))
else:
if cnt <= DP[idx][np][0]:
continue
DP[idx][np][0] = cnt
heappush(H, (-cnt, np, 0, idx))
print(max(DP[0][n - 1]))
print(max(DP[1][0]))
if __name__ == '__main__':
main()