結果

問題 No.1244 Black Segment
ユーザー rabimearabimea
提出日時 2023-01-25 03:01:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 203,992 KB
実行使用メモリ 9,604 KB
最終ジャッジ日時 2023-09-08 17:17:49
合計ジャッジ時間 6,529 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,764 KB
testcase_01 AC 4 ms
5,704 KB
testcase_02 AC 4 ms
5,704 KB
testcase_03 AC 3 ms
5,760 KB
testcase_04 AC 4 ms
5,792 KB
testcase_05 AC 4 ms
5,712 KB
testcase_06 AC 3 ms
5,700 KB
testcase_07 AC 3 ms
5,916 KB
testcase_08 AC 3 ms
5,764 KB
testcase_09 AC 3 ms
5,684 KB
testcase_10 AC 3 ms
5,708 KB
testcase_11 AC 4 ms
5,712 KB
testcase_12 AC 3 ms
5,784 KB
testcase_13 AC 4 ms
6,008 KB
testcase_14 AC 24 ms
7,048 KB
testcase_15 AC 4 ms
5,888 KB
testcase_16 AC 24 ms
7,092 KB
testcase_17 AC 4 ms
5,864 KB
testcase_18 AC 27 ms
8,144 KB
testcase_19 AC 35 ms
8,448 KB
testcase_20 AC 38 ms
8,928 KB
testcase_21 AC 38 ms
9,080 KB
testcase_22 AC 40 ms
8,920 KB
testcase_23 AC 41 ms
9,000 KB
testcase_24 AC 41 ms
8,972 KB
testcase_25 AC 41 ms
9,084 KB
testcase_26 AC 39 ms
8,896 KB
testcase_27 AC 41 ms
9,276 KB
testcase_28 AC 40 ms
9,160 KB
testcase_29 AC 40 ms
9,048 KB
testcase_30 AC 43 ms
9,164 KB
testcase_31 AC 41 ms
9,328 KB
testcase_32 AC 43 ms
9,160 KB
testcase_33 AC 42 ms
9,424 KB
testcase_34 AC 45 ms
9,604 KB
testcase_35 AC 41 ms
9,420 KB
testcase_36 AC 41 ms
9,376 KB
testcase_37 AC 41 ms
9,572 KB
testcase_38 AC 42 ms
9,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 1e5 + 11;
vi e[N];

int dis[N];
const int inf = 1e9;

int main() {
	ios :: sync_with_stdio(false);
	
	int n, m; cin >> n >> m;
	int a, b; cin >> a >> b;
	for(int i = 0; i < m; i ++) {
		int l, r; cin >> l >> r;
		e[l - 1].pb(r);
		e[r].pb(l - 1);
	}
	
	int S = n + 1, T = n + 2;
	for(int i = 0; i < a; i ++)
		e[S].pb(i);
	for(int i = b; i <= n; i ++)
		e[i].pb(T);
	
	fill(dis, dis + T + 1, inf);
	queue <int> q; q.push(S);
	dis[S] = 0;
	
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i : e[x])
			if(dis[i] == inf) {
				dis[i] = dis[x] + 1;
				q.push(i);
			}
	}
	
	int ans = (dis[T] == inf ? -1 : dis[T] - 2);
	cout << ans << '\n';
}
0