結果

問題 No.1995 CHIKA Road
ユーザー otoshigootoshigo
提出日時 2022-07-01 21:55:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 3,927 ms
コンパイル使用メモリ 216,376 KB
実行使用メモリ 33,524 KB
最終ジャッジ日時 2023-08-17 09:28:24
合計ジャッジ時間 6,133 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 11 ms
5,152 KB
testcase_07 AC 36 ms
8,756 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 38 ms
4,784 KB
testcase_11 AC 228 ms
33,524 KB
testcase_12 AC 139 ms
20,452 KB
testcase_13 AC 63 ms
13,040 KB
testcase_14 AC 66 ms
13,900 KB
testcase_15 AC 193 ms
29,808 KB
testcase_16 AC 18 ms
6,004 KB
testcase_17 AC 81 ms
14,468 KB
testcase_18 AC 144 ms
21,216 KB
testcase_19 AC 142 ms
21,256 KB
testcase_20 AC 71 ms
13,132 KB
testcase_21 AC 64 ms
12,196 KB
testcase_22 AC 133 ms
20,168 KB
testcase_23 AC 38 ms
8,792 KB
testcase_24 AC 116 ms
17,972 KB
testcase_25 AC 21 ms
6,344 KB
testcase_26 AC 44 ms
9,532 KB
testcase_27 AC 111 ms
17,568 KB
testcase_28 AC 64 ms
12,240 KB
testcase_29 AC 137 ms
20,796 KB
testcase_30 AC 20 ms
6,396 KB
testcase_31 AC 10 ms
4,996 KB
testcase_32 AC 26 ms
7,372 KB
testcase_33 AC 109 ms
17,332 KB
testcase_34 AC 11 ms
5,148 KB
testcase_35 AC 41 ms
9,292 KB
testcase_36 AC 48 ms
10,300 KB
testcase_37 AC 128 ms
19,200 KB
testcase_38 AC 88 ms
15,188 KB
testcase_39 AC 10 ms
4,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,a,b) for (int i = a; i < b; i++)
#define rrep2(i,a,b) for (int i = a-1; i >= b; i--)
#define rep3(i,a,b,c) for (int i = a; i < b; i+=c)
#define rrep3(i,a,b,c) for (int i = a-1; i >= b; i-=c)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int n,m;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    vector<int>V={0,n-1};
    map<int,vector<int>>G;
    rep(i,m){
        int a,b;cin>>a>>b;--a;--b;
        G[a].push_back(b);
        V.push_back(a);
        V.push_back(b);
    }
    sort(all(V));
    V.erase(unique(all(V)),V.end());
    int l=V.size();
    map<int,int>mp;
    rep(i,l){
        mp[V[i]]=i;
    }
    vector<ll>dp(l,1LL<<60);
    dp[0]=0;
    rep(i,l-1){
        chmin(dp[i+1],dp[i]+2*(V[i+1]-V[i]));
        for(auto b:G[V[i]]){
            int j=mp[b];
            chmin(dp[j],dp[i]+(2*b-2*V[i]-1));
        }
    }
    cout<<dp[l-1]<<"\n";
}
0