結果
| 問題 |
No.1995 CHIKA Road
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-01 22:00:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,100 bytes |
| コンパイル時間 | 268 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 1,701,624 KB |
| 最終ジャッジ日時 | 2024-11-26 05:01:51 |
| 合計ジャッジ時間 | 109,724 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 MLE * 1 |
| other | AC * 1 TLE * 6 MLE * 30 |
ソースコード
from collections import defaultdict
from heapq import heapify, heappop, heappush
n, m = map(int, input().split())
Edge = defaultdict(list)
A, B = set(), set()
for _ in range(m):
a, b = map(int, input().split())
Edge[a - 1].append((b - 1, 2 * b - 2 * a - 1))
A.add(a - 1)
B.add(b - 1)
for f in A:
for t in A:
if f < t:
Edge[f].append((t, 2 * (t - f)))
for t in B:
if f < t:
Edge[f].append((t, 2 * (t - f)))
Edge[f].append((n - 1, 2 * (n - 1 - f)))
for f in B:
for t in A:
if f < t:
Edge[f].append((t, 2 * (t - f)))
for t in B:
if f < t:
Edge[f].append((t, 2 * (t - f)))
Edge[f].append((n - 1, 2 * (n - 1 - f)))
INF = 10**18
DP = defaultdict(lambda: INF)
DP[0] = 0
H = [(0, 0)]
heapify(H)
while H:
ccost, cp = heappop(H)
if ccost > DP[cp]:
continue
if cp == n - 1:
print(ccost)
break
for np, dcost in Edge[cp]:
if ccost + dcost >= DP[np]:
continue
DP[np] = ccost + dcost
heappush(H, (ccost + dcost, np))