結果

問題 No.1244 Black Segment
ユーザー KudeKude
提出日時 2020-10-02 22:51:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 211,380 KB
実行使用メモリ 8,644 KB
最終ジャッジ日時 2023-09-24 22:24:10
合計ジャッジ時間 5,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 48 ms
4,480 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 47 ms
4,456 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 46 ms
6,768 KB
testcase_19 AC 59 ms
5,432 KB
testcase_20 AC 72 ms
6,668 KB
testcase_21 AC 71 ms
7,532 KB
testcase_22 AC 73 ms
6,836 KB
testcase_23 AC 79 ms
7,728 KB
testcase_24 AC 77 ms
7,308 KB
testcase_25 AC 74 ms
7,000 KB
testcase_26 AC 81 ms
8,120 KB
testcase_27 AC 91 ms
8,644 KB
testcase_28 AC 78 ms
6,672 KB
testcase_29 AC 83 ms
8,044 KB
testcase_30 AC 80 ms
7,512 KB
testcase_31 AC 85 ms
7,460 KB
testcase_32 AC 91 ms
7,856 KB
testcase_33 AC 89 ms
7,852 KB
testcase_34 AC 81 ms
7,628 KB
testcase_35 AC 68 ms
5,776 KB
testcase_36 AC 74 ms
6,452 KB
testcase_37 AC 77 ms
6,504 KB
testcase_38 AC 80 ms
7,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    a--;
    b -= a;
    VVI to(n-a+1);
    rep(_, m) {
        int l, r;
        cin >> l >> r;
        if (r <= a) continue;
        l--;
        if (l <= a) l = 0;
        else l -= a;
        r -= a;
        to[l].push_back(r);
        to[r].push_back(l);
    }
    queue<P> q;
    q.emplace(0, 0);
    vector<bool> visited(n-a+1);
    visited[0] = true;
    while(!q.empty()) {
        int u, k;
        tie(u, k) = q.front(); q.pop();
        for(int v: to[u]) {
            if (visited[v]) continue;
            visited[v] = true;
            if (v >= b) {
                cout << k + 1 << endl;
                return 0;
            }
            q.emplace(v, k+1);
        }
    }
    cout << -1 << endl;
}
0