結果

問題 No.1995 CHIKA Road
ユーザー pointNpointN
提出日時 2022-09-03 14:41:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 850 ms / 2,000 ms
コード長 1,761 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 161,716 KB
実行使用メモリ 79,708 KB
最終ジャッジ日時 2024-04-28 12:52:58
合計ジャッジ時間 12,254 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 26 ms
7,808 KB
testcase_07 AC 112 ms
17,664 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 96 ms
7,472 KB
testcase_11 AC 850 ms
79,708 KB
testcase_12 AC 512 ms
42,780 KB
testcase_13 AC 221 ms
28,660 KB
testcase_14 AC 226 ms
30,124 KB
testcase_15 AC 724 ms
70,536 KB
testcase_16 AC 50 ms
10,496 KB
testcase_17 AC 265 ms
32,364 KB
testcase_18 AC 524 ms
50,432 KB
testcase_19 AC 500 ms
50,676 KB
testcase_20 AC 235 ms
29,348 KB
testcase_21 AC 209 ms
27,244 KB
testcase_22 AC 467 ms
48,008 KB
testcase_23 AC 121 ms
18,048 KB
testcase_24 AC 392 ms
42,156 KB
testcase_25 AC 59 ms
11,520 KB
testcase_26 AC 135 ms
20,484 KB
testcase_27 AC 382 ms
41,068 KB
testcase_28 AC 207 ms
26,988 KB
testcase_29 AC 475 ms
48,992 KB
testcase_30 AC 56 ms
11,440 KB
testcase_31 AC 27 ms
7,424 KB
testcase_32 AC 82 ms
14,080 KB
testcase_33 AC 347 ms
40,424 KB
testcase_34 AC 30 ms
7,936 KB
testcase_35 AC 124 ms
19,328 KB
testcase_36 AC 152 ms
21,968 KB
testcase_37 AC 436 ms
45,284 KB
testcase_38 AC 298 ms
34,456 KB
testcase_39 AC 27 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N,M; cin >> N >> M;
  set<int> st;
  st.insert(1);
  st.insert(N);
  map<int,vector<int>> G;
  map<int,vector<ll>> CO;
  rep(i,M){
    int a,b; cin >> a >> b;
    G[a].pb(b);
    CO[a].pb(2*b-2*a-1);
    st.insert(a);
    st.insert(b);
  }
  vector<int> vst;
  for(auto s:st){
    vst.pb(s);
  }
  rep(i,sz(vst)-1){
    int a = vst[i];
    int b = vst[i+1];
    G[a].pb(b);
    CO[a].pb(2*(b-a));
  }
  map<int,ll> D;
  set<int> used;
  priority_queue<pair<ll,int>,
                 vector<pair<ll,int>>,
                 greater<pair<ll,int>>> q;
  q.push({(ll)0,1});
  while(!q.empty()){
    ll d = q.top().first; int to = q.top().second; q.pop();
    if(used.count(to)) continue;
    used.insert(to); D[to] = d;
    rep(i,sz(G[to])){
      int nxt=G[to][i];
      if(D.count(nxt) && D[nxt] <= D[to] + CO[to][i]) continue;
      q.push({D[to] + CO[to][i], nxt});
    }
  }
  cout << D[N] << endl;
  return 0;
}
0