結果
問題 | No.614 壊れたキャンパス |
ユーザー |
|
提出日時 | 2017-12-14 14:55:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,650 bytes |
コンパイル時間 | 1,219 ms |
コンパイル使用メモリ | 110,184 KB |
最終ジャッジ日時 | 2025-01-05 05:23:51 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%d%d%d%d%d", &N, &M, &K, &S, &T); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:28:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d%d%d", &a, &b, &c); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>#include <algorithm>#include <unordered_map>#include <queue>using namespace std;using i64 = long long;constexpr i64 inf = 987654321987654321LL;int N, M, K, S, T;int a, b, c;i64 cc; int p, q;i64 _cost;i64 mini;int k; i64 v;int src, dst;int dif;int main(void) {scanf("%d%d%d%d%d", &N, &M, &K, &S, &T);--S, --T;priority_queue<tuple<i64, int, int>, vector<tuple<i64, int, int>>, greater<tuple<i64, int, int>>> pq;// コスト, 棟, 階pq.emplace(0, 0, S);vector<unordered_map<int, i64>> cost(N); // cost[棟][階] := 最小コストcost[0][S] = 0;vector<vector<pair<int, int>>> G(N, vector<pair<int, int>>()); // G[i] := {(i棟の出次階, i+1棟の入次階)のリスト}for(int i=0; i<M; ++i) {scanf("%d%d%d", &a, &b, &c);--a, --b, --c;G[a].emplace_back(b, c);}mini = inf;while(!pq.empty()) {// 今 p棟 q階にいる。tie(cc, p, q) = pq.top(); pq.pop();if(!cost[p].count(q)) { continue; }_cost = cost[p][q];if(p == N-1) {mini = min(mini, _cost + abs(T - q));}if(_cost < cc) { continue; }// 同棟の src 階に移動し、// 渡り廊下で p+1棟 dst階に移動するfor(auto&& pr : G[p]) {dif = abs(q - pr.first);if(!cost[p+1].count(pr.second) || cost[p+1][pr.second] > _cost + dif) {cost[p+1][pr.second] = _cost + dif;pq.emplace(cost[p+1][pr.second], p+1, pr.second);}}}// mini = inf;// for(auto&& kv : cost[N-1]) {// mini = min(mini, kv.second + abs(T - kv.first));// }if(mini == inf) { mini = -1; }printf("%lld\n", mini);return 0;}