結果

問題 No.1244 Black Segment
ユーザー auauaauaua
提出日時 2020-10-02 22:59:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,667 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 174,320 KB
実行使用メモリ 21,224 KB
最終ジャッジ日時 2023-09-24 22:37:54
合計ジャッジ時間 6,631 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,148 KB
testcase_01 AC 5 ms
9,260 KB
testcase_02 AC 6 ms
9,228 KB
testcase_03 AC 5 ms
9,136 KB
testcase_04 AC 5 ms
9,108 KB
testcase_05 AC 6 ms
9,200 KB
testcase_06 AC 5 ms
9,120 KB
testcase_07 AC 6 ms
9,124 KB
testcase_08 AC 5 ms
9,116 KB
testcase_09 AC 5 ms
9,208 KB
testcase_10 AC 5 ms
8,992 KB
testcase_11 AC 5 ms
9,136 KB
testcase_12 AC 6 ms
9,300 KB
testcase_13 AC 9 ms
9,740 KB
testcase_14 AC 79 ms
20,680 KB
testcase_15 AC 8 ms
9,604 KB
testcase_16 AC 78 ms
20,140 KB
testcase_17 AC 7 ms
9,528 KB
testcase_18 AC 93 ms
15,000 KB
testcase_19 AC 139 ms
18,864 KB
testcase_20 AC 140 ms
18,456 KB
testcase_21 AC 108 ms
17,848 KB
testcase_22 AC 147 ms
18,420 KB
testcase_23 AC 155 ms
18,292 KB
testcase_24 AC 146 ms
18,796 KB
testcase_25 AC 141 ms
18,848 KB
testcase_26 AC 133 ms
17,272 KB
testcase_27 AC 128 ms
18,884 KB
testcase_28 AC 149 ms
19,148 KB
testcase_29 AC 133 ms
18,276 KB
testcase_30 AC 148 ms
18,704 KB
testcase_31 AC 133 ms
18,380 KB
testcase_32 AC 128 ms
18,336 KB
testcase_33 AC 131 ms
18,400 KB
testcase_34 AC 163 ms
19,256 KB
testcase_35 AC 142 ms
21,224 KB
testcase_36 AC 143 ms
20,780 KB
testcase_37 AC 159 ms
20,668 KB
testcase_38 AC 132 ms
18,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=200010;
ll n;
vector<vector<pll> >G(200010);
vector<ll> d(200010);
void dijkstra(ll s,vector<vector<pll> >&G,vector<ll> &d){
    priority_queue<pll,vector<pll>,greater<pll> >pq;
    rep(i,n){
        d[i]=inf*inf;
    }
    d[s]=0;
    pq.push(mp(0,s));
    while(!pq.empty()){
        pll k=pq.top();pq.pop();
        ll v=k.second;
        if(d[v]<k.first)continue;
        for(auto e:G[v]){
            if(d[e.first]>d[v]+e.second){
                d[e.first]=d[v]+e.second;
                pq.push(mp(d[e.first],e.first));
            }
        }
    }
}
signed main(){
    ll n_,m,a,b;cin>>n_>>m>>a>>b;
    n=n_*2+4;
    rep(i,m){
        ll l,r;
        cin>>l>>r;
        if(l<a)G[a].pb(mp(l,0));
        G[l].pb(mp(r+1,1));
        G[l].pb(mp(n_+2+r,1));
        G[r+n_+2].pb(mp(l,1));
        G[r+n_+2].pb(mp(l-1+n_+2,1));
    }
    dijkstra(a,G,d);
    ll ans=inf*inf;
    REP(i,b+1,n_+2){
        ans=min(ans,d[i]);
    }
    rep(i,n_+2){
        //cout<<i<<' '<<d[i]<<endl;
    }
    if(ans>inf){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
}
0