結果

問題 No.1995 CHIKA Road
ユーザー Nzt3Nzt3
提出日時 2022-07-01 22:18:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 215,228 KB
実行使用メモリ 21,428 KB
最終ジャッジ日時 2023-08-17 09:50:45
合計ジャッジ時間 5,914 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 10 ms
4,616 KB
testcase_07 AC 31 ms
7,332 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 62 ms
9,244 KB
testcase_11 AC 157 ms
21,428 KB
testcase_12 AC 82 ms
13,380 KB
testcase_13 AC 46 ms
9,308 KB
testcase_14 AC 52 ms
9,908 KB
testcase_15 AC 133 ms
19,548 KB
testcase_16 AC 15 ms
5,060 KB
testcase_17 AC 66 ms
10,836 KB
testcase_18 AC 114 ms
16,216 KB
testcase_19 AC 115 ms
16,196 KB
testcase_20 AC 59 ms
10,264 KB
testcase_21 AC 55 ms
9,704 KB
testcase_22 AC 109 ms
15,628 KB
testcase_23 AC 32 ms
7,048 KB
testcase_24 AC 94 ms
14,192 KB
testcase_25 AC 19 ms
5,508 KB
testcase_26 AC 37 ms
8,052 KB
testcase_27 AC 89 ms
14,008 KB
testcase_28 AC 54 ms
9,820 KB
testcase_29 AC 109 ms
16,120 KB
testcase_30 AC 18 ms
5,368 KB
testcase_31 AC 9 ms
4,376 KB
testcase_32 AC 24 ms
6,032 KB
testcase_33 AC 87 ms
13,616 KB
testcase_34 AC 10 ms
4,436 KB
testcase_35 AC 35 ms
7,592 KB
testcase_36 AC 41 ms
8,404 KB
testcase_37 AC 104 ms
15,172 KB
testcase_38 AC 73 ms
11,712 KB
testcase_39 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<int>zatu={0,N-1};
  vector<array<int,2>>A(M);
  for(int i=0;i<M;i++){
    cin>>A[i][0]>>A[i][1];
    --A[i][0],--A[i][1];
    zatu.push_back(A[i][0]),
    zatu.push_back(A[i][1]);
  }
  sort(zatu.begin(),zatu.end());
  zatu.erase(unique(zatu.begin(),zatu.end()),zatu.end());
  int N2=zatu.size();
  vector<vector<array<long long,2>>>G(N2);

  for(int i=0;i<N2-1;i++){
    G[i].push_back({i+1,(zatu[i+1]-zatu[i])*2});
  }
  for(auto i:A){
    G[lower_bound(zatu.begin(),zatu.end(),i[0])-zatu.begin()].push_back({(long long)(lower_bound(zatu.begin(),zatu.end(),i[1])-zatu.begin()),(long long)(i[1]-i[0])*2-1});
  }
  vector<long long>dist(N2,1e12);
  dist[0]=0;
  priority_queue<array<long long,2>,vector<array<long long,2>>,greater<array<long long,2>>>dijk;
  dijk.push({0,0});
  while(dijk.size()){
    long long d=dijk.top()[0],v=dijk.top()[1];
    dijk.pop();
    if(d>dist[v])continue;
    for(auto i:G[v]){
      if(dist[i[0]]>d+i[1]){
        dist[i[0]]=d+i[1];
        dijk.push({d+i[1],i[0]});
      }
    }
  }
  cout<<dist.back()<<'\n';
}
0