結果

問題 No.1995 CHIKA Road
ユーザー yansi819yansi819
提出日時 2024-04-14 20:09:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 723 ms / 2,000 ms
コード長 1,231 bytes
コンパイル時間 5,159 ms
コンパイル使用メモリ 271,348 KB
実行使用メモリ 49,080 KB
最終ジャッジ日時 2024-04-14 20:09:52
合計ジャッジ時間 14,642 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,812 KB
testcase_04 AC 2 ms
6,812 KB
testcase_05 AC 2 ms
6,812 KB
testcase_06 AC 21 ms
6,812 KB
testcase_07 AC 89 ms
12,544 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 117 ms
13,648 KB
testcase_11 AC 723 ms
49,080 KB
testcase_12 AC 355 ms
30,592 KB
testcase_13 AC 161 ms
18,816 KB
testcase_14 AC 174 ms
19,584 KB
testcase_15 AC 577 ms
43,548 KB
testcase_16 AC 40 ms
7,936 KB
testcase_17 AC 218 ms
21,888 KB
testcase_18 AC 401 ms
33,620 KB
testcase_19 AC 403 ms
33,832 KB
testcase_20 AC 211 ms
20,096 KB
testcase_21 AC 223 ms
18,816 KB
testcase_22 AC 381 ms
32,084 KB
testcase_23 AC 91 ms
12,672 KB
testcase_24 AC 313 ms
28,580 KB
testcase_25 AC 47 ms
8,832 KB
testcase_26 AC 115 ms
14,336 KB
testcase_27 AC 383 ms
27,788 KB
testcase_28 AC 168 ms
18,688 KB
testcase_29 AC 373 ms
32,728 KB
testcase_30 AC 41 ms
8,576 KB
testcase_31 AC 19 ms
6,940 KB
testcase_32 AC 58 ms
10,240 KB
testcase_33 AC 292 ms
27,308 KB
testcase_34 AC 23 ms
6,940 KB
testcase_35 AC 116 ms
13,440 KB
testcase_36 AC 137 ms
15,488 KB
testcase_37 AC 349 ms
30,720 KB
testcase_38 AC 239 ms
23,576 KB
testcase_39 AC 17 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  ll n, m; cin >> n >> m;
  set<ll> st {1, n};
  vector<vector<ll>> edge(m);
  for (ll i = 0; i < m; i++) {
    ll a, b; cin >> a >> b;
    st.insert(a); st.insert(b);
    edge[i] = {a, b};
  }
  ll N = st.size();
  ll cnt = 0, last = -1;
  vector<vector<pair<ll, ll>>> g(N);
  map<ll, ll> mp;
  for (auto it = st.begin(); it != st.end(); it++) {
    mp[*it] = cnt;
    cnt++;
    if (last > -1) {
      g[mp[last]].push_back({mp[*it], 2 * (*it) - 2 * last});
    }
    last = *it;
  }
  for (auto &e: edge) {
    ll a = mp[e[0]], b = mp[e[1]];
    g[a].push_back({b, 2 * e[1] - 2 * e[0] - 1});
  }

  vector<ll> dis(N, 1e18);
  dis[0] = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  que.push({0, 0});
  while (!que.empty()) {
    auto q = que.top(); que.pop();
    ll u = q.second;
    for (auto p: g[u]) {
      ll v = p.first;
      ll c = p.second;
      if (dis[v] > dis[u] + c) {
        dis[v] = dis[u] + c;
        que.push({dis[v], v});
      }
    }
  }
  cout << dis[N - 1] << endl;
  return 0;
}
0