結果

問題 No.1244 Black Segment
ユーザー auauaauaua
提出日時 2020-10-02 22:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,722 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 176,352 KB
実行使用メモリ 19,756 KB
最終ジャッジ日時 2023-09-24 22:36:27
合計ジャッジ時間 6,349 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,664 KB
testcase_01 AC 5 ms
8,388 KB
testcase_02 AC 5 ms
8,284 KB
testcase_03 AC 6 ms
8,676 KB
testcase_04 AC 6 ms
8,348 KB
testcase_05 AC 6 ms
8,352 KB
testcase_06 AC 6 ms
8,536 KB
testcase_07 AC 6 ms
8,608 KB
testcase_08 AC 5 ms
8,412 KB
testcase_09 AC 5 ms
8,476 KB
testcase_10 AC 6 ms
8,380 KB
testcase_11 AC 6 ms
8,588 KB
testcase_12 AC 6 ms
8,516 KB
testcase_13 AC 9 ms
8,924 KB
testcase_14 AC 79 ms
19,756 KB
testcase_15 AC 9 ms
8,856 KB
testcase_16 AC 78 ms
19,432 KB
testcase_17 AC 8 ms
8,892 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

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=100010;
vector<ll>dp(MAX);
vector<ll>l(MAX);
vector<ll>r(MAX);
ll n;
vector<vector<pll> >G(100010);
vector<ll> d(100010);
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