結果

問題 No.614 壊れたキャンパス
ユーザー legosukelegosuke
提出日時 2017-12-14 17:16:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 165,136 KB
実行使用メモリ 814,508 KB
最終ジャッジ日時 2023-08-21 04:34:01
合計ジャッジ時間 3,913 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,192 KB
testcase_01 AC 4 ms
8,012 KB
testcase_02 AC 5 ms
8,088 KB
testcase_03 WA -
testcase_04 AC 5 ms
8,016 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

map<pii, ll> mp;
map<pii, pii> pre;
int n, m, k, s, t;
vector<int> v[200010];

ll rec(pii x) {
  if (mp[x]) return mp[x];
  ll res = 1LL << 60;
  for (int i = 0; i < v[x.first].size(); i++) {
    res = min(res, rec(pre[x]) + abs(x.second - v[x.first][i]));
  }
  return mp[x] = res;
}

int main(void) {
  cin >> n >> m >> k >> s >> t;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    v[a].push_back(b);
    v[a + 1].push_back(c);
    pre[pii(a + 1, c)] = pii(a, b);
  }
  for (int i = 1; i <= n; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 0; i < v[1].size(); i++) {
    pre[pii(1, v[1][i])] = pii(1, s);
    mp[pii(1, v[1][i])] = abs(v[1][i] - s);
  }

  ll ans = 1LL << 60;
  for (int i = 0; i < v[n].size(); i++) {
    ans = min(ans, rec(pii(n, v[n][i])) + abs(t - v[n][i]));
  }
  cout << (ans == 1LL << 60 ? -1 : ans) << endl;
  
  return 0;
}
0