結果

問題 No.1244 Black Segment
ユーザー 👑 jupirojupiro
提出日時 2020-10-02 23:19:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,052 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 137,124 KB
実行使用メモリ 9,712 KB
最終ジャッジ日時 2023-09-24 23:28:33
合計ジャッジ時間 24,169 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 41 ms
4,376 KB
testcase_14 AC 344 ms
4,840 KB
testcase_15 AC 36 ms
4,380 KB
testcase_16 AC 156 ms
4,616 KB
testcase_17 AC 13 ms
4,376 KB
testcase_18 AC 838 ms
7,068 KB
testcase_19 AC 815 ms
7,204 KB
testcase_20 AC 947 ms
8,048 KB
testcase_21 AC 1,111 ms
8,120 KB
testcase_22 AC 995 ms
7,852 KB
testcase_23 AC 1,280 ms
7,992 KB
testcase_24 AC 1,181 ms
8,376 KB
testcase_25 AC 981 ms
8,260 KB
testcase_26 AC 1,420 ms
8,308 KB
testcase_27 AC 1,129 ms
9,664 KB
testcase_28 AC 1,273 ms
8,536 KB
testcase_29 AC 1,576 ms
8,644 KB
testcase_30 AC 1,062 ms
8,584 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 49 ms
8,380 KB
testcase_35 AC 31 ms
9,588 KB
testcase_36 AC 364 ms
9,712 KB
testcase_37 AC 595 ms
8,400 KB
testcase_38 AC 668 ms
8,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 5000000;


int f(int a, int b) {
	return min(a, b);
}
template< typename Monoid >
struct SegmentTree {
	//using F = function< Monoid(Monoid, Monoid) >;

	int sz;
	vector< Monoid > seg;

	//const F f;
	const Monoid M1;

	SegmentTree(int n, /*const F f,*/ const Monoid& M1) : /*f(f),*/ M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid& x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid& x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		if (a >= b) return M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}
};

void solve() {
	int n, m, A, B; cin >> n >> m >> A >> B;
	A--; B--;
	vector<pair<int, int>> vp(m);
	for (int i = 0; i < m; i++) cin >> vp[i].first >> vp[i].second, vp[i].first--, vp[i].second--;
	vector<vector<int>> R(n);
	for (int i = 0; i < m; i++) {
		if (vp[i].first <= A and A <= vp[i].second) vp[i].first = A;
		if (vp[i].first <= B and vp[i].second >= B) vp[i].second = B;
		R[vp[i].first].emplace_back(vp[i].second);
	}
	vector<int> dp(n, inf);
	for (int kkt = 0; kkt <= 1500; kkt++) {
		for (int i = A; i <= B; i++) {
			if (i != A) {
				for (auto r : R[i]) {
					chmin(dp[i - 1], dp[r] + 1);
				}
			}
			for (auto r : R[i]) {
				//cout << i << " " << r << endl;
				if (i == A) {
					chmin(dp[r], 1);
				}
				else {
					chmin(dp[r], dp[i - 1] + 1);
				}
			}
			//for (int i = A; i <= B; i++) cout << i << " " << dp[i] << endl;
		}
	}
	if (dp[B] == inf) cout << -1 << "\n";
	else cout << dp[B] << "\n";
}

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int kkt = 1; while (kkt--) solve();
}
0