結果

問題 No.1244 Black Segment
ユーザー milanis48663220milanis48663220
提出日時 2020-10-02 23:13:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,562 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 91,372 KB
実行使用メモリ 16,236 KB
最終ジャッジ日時 2023-09-24 23:15:35
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,780 KB
testcase_01 AC 3 ms
5,776 KB
testcase_02 AC 3 ms
5,728 KB
testcase_03 AC 4 ms
5,784 KB
testcase_04 AC 3 ms
5,776 KB
testcase_05 AC 3 ms
5,708 KB
testcase_06 AC 3 ms
5,784 KB
testcase_07 AC 3 ms
5,716 KB
testcase_08 AC 3 ms
5,904 KB
testcase_09 AC 4 ms
6,000 KB
testcase_10 AC 3 ms
5,716 KB
testcase_11 AC 3 ms
5,852 KB
testcase_12 AC 3 ms
5,716 KB
testcase_13 AC 5 ms
6,048 KB
testcase_14 AC 28 ms
11,368 KB
testcase_15 AC 5 ms
6,060 KB
testcase_16 AC 28 ms
11,504 KB
testcase_17 AC 5 ms
6,120 KB
testcase_18 AC 48 ms
10,992 KB
testcase_19 AC 67 ms
13,012 KB
testcase_20 AC 68 ms
13,224 KB
testcase_21 AC 49 ms
12,992 KB
testcase_22 AC 69 ms
13,160 KB
testcase_23 AC 69 ms
13,132 KB
testcase_24 AC 61 ms
13,668 KB
testcase_25 AC 69 ms
13,692 KB
testcase_26 AC 59 ms
12,704 KB
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 <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll INF = 1e+15;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
};

vector<edge> G[100000];
ll d[100000];

void dijkstra(int s, int num_v){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+num_v, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int N, M, A, B;
int L[100000], R[100000];


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> A >> B;
    A--;// B--;
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i]; L[i]--; R[i]--;
    }
    for(int i = 0; i < A; i++){
        G[i].push_back((edge){i+1, 0});
    }
    for(int i = B; i < N; i++){
        G[i].push_back((edge){i+1, 0});
    }
    for(int i = 0; i < M; i++){
        G[L[i]].push_back((edge){R[i]+1, 1});
        G[R[i]+1].push_back((edge){L[i], 1});
    }
    dijkstra(0, N+1);
    // for(int i = 0; i <= N; i++) cout << d[i] << ' ';
    // cout << endl;
    if(d[N] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << d[N] << endl;
}
0