結果
問題 | No.614 壊れたキャンパス |
ユーザー | startcpp |
提出日時 | 2017-12-29 21:28:52 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 917 ms / 2,000 ms |
コード長 | 2,479 bytes |
コンパイル時間 | 1,062 ms |
コンパイル使用メモリ | 83,280 KB |
実行使用メモリ | 82,108 KB |
最終ジャッジ日時 | 2024-06-01 06:43:14 |
合計ジャッジ時間 | 11,679 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 13 ms
26,752 KB |
testcase_01 | AC | 13 ms
26,752 KB |
testcase_02 | AC | 12 ms
26,752 KB |
testcase_03 | AC | 13 ms
26,752 KB |
testcase_04 | AC | 13 ms
26,752 KB |
testcase_05 | AC | 12 ms
26,752 KB |
testcase_06 | AC | 12 ms
26,880 KB |
testcase_07 | AC | 13 ms
26,752 KB |
testcase_08 | AC | 818 ms
76,252 KB |
testcase_09 | AC | 778 ms
78,072 KB |
testcase_10 | AC | 770 ms
75,056 KB |
testcase_11 | AC | 848 ms
76,024 KB |
testcase_12 | AC | 917 ms
75,856 KB |
testcase_13 | AC | 851 ms
76,044 KB |
testcase_14 | AC | 827 ms
76,244 KB |
testcase_15 | AC | 691 ms
75,264 KB |
testcase_16 | AC | 759 ms
75,640 KB |
testcase_17 | AC | 433 ms
71,784 KB |
testcase_18 | AC | 495 ms
82,108 KB |
testcase_19 | AC | 377 ms
73,128 KB |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <algorithm> #include <queue> #include <functional> #define int long long using namespace std; typedef pair<int, int> P; int INF = 1e+15; int n, m, k, s, t; int a[200000], b[200000], c[200000]; vector<P> points; vector<int> heights[200001]; vector<int> edgeTo[400002]; vector<int> edgeCost[400002]; int dijkstra(int start, int goal) { static int minCost[400002]; static priority_queue<P, vector<P>, greater<P>> que; int i; for (i = 0; i < points.size(); i++) minCost[i] = INF; que.push(P(0, start)); while (!que.empty()) { P now = que.top(); que.pop(); int cst = now.first; int pos = now.second; if (minCost[pos] <= cst) continue; minCost[pos] = cst; if (pos == goal) break; for (i = 0; i < edgeTo[pos].size(); i++) { que.push(P(edgeCost[pos][i] + cst, edgeTo[pos][i])); } } return minCost[goal]; } signed main() { int i, j; cin >> n >> m >> k >> s >> t; for (i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; points.push_back(P(a[i], b[i])); points.push_back(P(a[i] + 1, c[i])); heights[a[i]].push_back(b[i]); heights[a[i] + 1].push_back(c[i]); } points.push_back(P(1, s)); points.push_back(P(n, t)); sort(points.begin(), points.end()); points.erase(unique(points.begin(), points.end()), points.end()); heights[1].push_back(s); heights[n].push_back(t); for (i = 1; i <= n; i++) sort(heights[i].begin(), heights[i].end()); for (i = 0; i < m; i++) { int from = lower_bound(points.begin(), points.end(), P(a[i], b[i])) - points.begin(); int to = lower_bound(points.begin(), points.end(), P(a[i] + 1, c[i])) - points.begin(); edgeTo[from].push_back(to); edgeCost[from].push_back(0); } for (i = 1; i <= n; i++) { for (j = 0; j + 1 < heights[i].size(); j++) { int from = lower_bound(points.begin(), points.end(), P(i, heights[i][j])) - points.begin(); int to = lower_bound(points.begin(), points.end(), P(i, heights[i][j + 1])) - points.begin(); edgeTo[from].push_back(to); edgeTo[to].push_back(from); edgeCost[from].push_back(heights[i][j + 1] - heights[i][j]); edgeCost[to].push_back(heights[i][j + 1] - heights[i][j]); } } int start = lower_bound(points.begin(), points.end(), P(1, s)) - points.begin(); int goal = lower_bound(points.begin(), points.end(), P(n, t)) - points.begin(); int minCost = dijkstra(start, goal); if (minCost >= INF) cout << -1 << endl; else cout << minCost << endl; return 0; }