結果

問題 No.1244 Black Segment
ユーザー どららどらら
提出日時 2020-10-03 12:58:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 171,508 KB
実行使用メモリ 10,736 KB
最終ジャッジ日時 2023-09-25 05:05:01
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,072 KB
testcase_01 AC 4 ms
6,132 KB
testcase_02 AC 4 ms
6,352 KB
testcase_03 AC 4 ms
6,412 KB
testcase_04 AC 4 ms
6,076 KB
testcase_05 AC 4 ms
6,084 KB
testcase_06 AC 4 ms
6,084 KB
testcase_07 AC 4 ms
6,084 KB
testcase_08 AC 4 ms
6,088 KB
testcase_09 AC 4 ms
6,072 KB
testcase_10 AC 4 ms
6,144 KB
testcase_11 AC 4 ms
6,096 KB
testcase_12 AC 4 ms
6,088 KB
testcase_13 AC 6 ms
6,340 KB
testcase_14 AC 61 ms
10,108 KB
testcase_15 AC 6 ms
6,272 KB
testcase_16 AC 55 ms
8,992 KB
testcase_17 AC 5 ms
6,200 KB
testcase_18 AC 51 ms
8,492 KB
testcase_19 AC 78 ms
10,084 KB
testcase_20 AC 81 ms
9,292 KB
testcase_21 AC 73 ms
9,036 KB
testcase_22 AC 83 ms
9,192 KB
testcase_23 AC 96 ms
9,528 KB
testcase_24 AC 87 ms
9,468 KB
testcase_25 AC 78 ms
8,996 KB
testcase_26 AC 86 ms
9,332 KB
testcase_27 AC 96 ms
9,200 KB
testcase_28 AC 88 ms
9,424 KB
testcase_29 AC 95 ms
9,656 KB
testcase_30 AC 84 ms
8,996 KB
testcase_31 AC 92 ms
9,200 KB
testcase_32 AC 96 ms
9,160 KB
testcase_33 AC 94 ms
9,200 KB
testcase_34 AC 60 ms
8,740 KB
testcase_35 AC 60 ms
8,244 KB
testcase_36 AC 69 ms
8,476 KB
testcase_37 AC 97 ms
10,736 KB
testcase_38 AC 92 ms
10,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct Edge {
  int src, dest;
  int dist;
};
bool operator>(const Edge& a, const Edge& b){
  return a.dist > b.dist;
}

vector<Edge> G[100005];
int dp[100005];

int solve(int s, int t){
  rep(i,100005) dp[i] = -1;

  priority_queue<Edge,vector<Edge>,greater<Edge>> q;
  q.push((Edge){-1,s,0});

  while(!q.empty()){
    Edge e=q.top();
    q.pop();
    if(dp[e.dest] != -1) continue;
    dp[e.dest] = e.dist;
    FOR(it,G[e.dest])
      if(dp[it->dest]==-1) q.push((Edge){it->src,it->dest,e.dist+it->dist});
  }

  return dp[t];
}


int main(){
  int N, M, A, B;
  cin >> N >> M >> A >> B;
  int s = 0;
  int t = 100004;

  rep(i,M){
    int l, r;
    cin >> l >> r;
    r++;
    if(l<=A) l = s;
    if(r<=A) r = s;
    if(l>=B+1) l = t;
    if(r>=B+1) r = t;
    G[l].push_back((Edge){l,r,1});
    G[r].push_back((Edge){r,l,1});
  }
  
  cout << solve(s, t) << endl;
  
  return 0;
}

0