結果
| 問題 | No.614 壊れたキャンパス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-14 11:58:05 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,538 bytes |
| 記録 | |
| コンパイル時間 | 1,271 ms |
| コンパイル使用メモリ | 99,276 KB |
| 実行使用メモリ | 48,552 KB |
| 最終ジャッジ日時 | 2024-12-14 12:34:48 |
| 合計ジャッジ時間 | 21,109 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 WA * 2 TLE * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | i64 N, M, K, S, T; scanf("%lld%lld%lld%lld%lld", &N, &M, &K, &S, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | i64 a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
using i64 = long long;
int main(void) {
constexpr i64 inf = 987654321987654321LL;
i64 N, M, K, S, T; scanf("%lld%lld%lld%lld%lld", &N, &M, &K, &S, &T);
--S, --T;
map<pair<i64, i64>, i64> G; // G[(棟, 階)] := 右棟の階
priority_queue<tuple<i64, i64, i64>, vector<tuple<i64, i64, i64>>, greater<tuple<i64, i64, i64>>> pq;
// コスト, 棟, 階
pq.emplace(0, 0, S);
vector<map<i64, i64>> cost(N);
// cost[棟][階] := 最小コスト
cost[0][S] = 0;
vector<vector<i64>> outdegs(N, vector<i64>()); // outdegs[i] = {i棟において、出次のある階のリスト}
for(i64 i=0; i<M; ++i) {
i64 a, b, c; scanf("%lld%lld%lld", &a, &b, &c);
--a, --b, --c;
G[make_pair(a, b)] = c;
outdegs[a].push_back(b);
}
while(!pq.empty()) {
// 今 p棟 q階にいる。
i64 _, p, q; tie(_, p, q) = pq.top(); pq.pop();
// 同棟の x 階に移動する
for(i64& x : outdegs[p]) {
// 渡り廊下で p+1棟 dst階に移動する
i64 dst = G[make_pair(p, x)];
if(!cost[p+1].count(dst) || cost[p+1][dst] > cost[p][q] + abs(q - x)) {
cost[p+1][dst] = cost[p][q] + abs(q - x);
pq.emplace(cost[p+1][dst], p+1, dst);
}
}
}
i64 mini = inf;
for(auto&& kv : cost[N-1]) {
i64 k, v; tie(k, v) = kv; // k階まででコストvかかった
mini = min(mini, v + abs(T - k));
}
if(mini == inf) { mini = -1; }
printf("%lld\n", mini);
return 0;
}