結果

問題 No.1244 Black Segment
ユーザー carrot46carrot46
提出日時 2020-10-02 22:51:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 177,328 KB
実行使用メモリ 12,224 KB
最終ジャッジ日時 2023-09-24 22:23:52
合計ジャッジ時間 5,758 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 53 ms
6,068 KB
testcase_15 AC 4 ms
4,384 KB
testcase_16 AC 52 ms
6,156 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 61 ms
8,568 KB
testcase_19 AC 90 ms
9,768 KB
testcase_20 AC 97 ms
10,164 KB
testcase_21 AC 85 ms
10,112 KB
testcase_22 AC 102 ms
10,260 KB
testcase_23 AC 108 ms
10,020 KB
testcase_24 AC 104 ms
10,620 KB
testcase_25 AC 100 ms
10,584 KB
testcase_26 AC 96 ms
9,748 KB
testcase_27 AC 92 ms
9,248 KB
testcase_28 AC 101 ms
10,560 KB
testcase_29 AC 93 ms
10,192 KB
testcase_30 AC 101 ms
10,756 KB
testcase_31 AC 97 ms
10,120 KB
testcase_32 AC 99 ms
10,036 KB
testcase_33 AC 97 ms
10,028 KB
testcase_34 AC 116 ms
11,472 KB
testcase_35 AC 100 ms
12,224 KB
testcase_36 AC 100 ms
11,708 KB
testcase_37 AC 106 ms
12,016 KB
testcase_38 AC 99 ms
10,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N>>M>>A>>B;
    mat G(N + 3, vec(0));
    const int st = 0, gl = N + 2;
    rep(i, M){
        int l, r; cin>>l>>r; ++r;
        G[l].push_back(r);
        G[r].push_back(l);
    }
    rep(i, A) G[st].push_back(i + 1);
    reps(i, B + 1, gl) G[i].push_back(gl);
    vec dist(N + 3, INF);
    dist[st] = 0;
    priority_queue<P, vector<P>, greater<> > pque;
    pque.emplace(0, st);
    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        if(dist[p.se] < p.fi) continue;
        for(ll to : G[p.se]){
            if(chmin(dist[to], p.fi + 1)){
                pque.emplace(p.fi + 1, to);
            }
        }
    }
    cout<<(dist[gl] == INF ? -1 : dist[gl] - 2)<<endl;
}
0