結果

問題 No.614 壊れたキャンパス
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-12-14 11:58:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 1,065 ms
コンパイル使用メモリ 100,080 KB
実行使用メモリ 35,412 KB
最終ジャッジ日時 2024-05-08 09:39:18
合計ジャッジ時間 8,583 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
25,308 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 TLE -
testcase_09 AC 868 ms
35,412 KB
testcase_10 AC 323 ms
33,280 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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;
}
0