結果

問題 No.2543 Many Meetings
ユーザー shobonvipshobonvip
提出日時 2023-11-24 21:49:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 2,056 bytes
コンパイル時間 4,717 ms
コンパイル使用メモリ 272,164 KB
実行使用メモリ 43,368 KB
最終ジャッジ日時 2023-11-24 21:49:15
合計ジャッジ時間 11,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 235 ms
43,368 KB
testcase_04 AC 235 ms
43,368 KB
testcase_05 AC 262 ms
43,368 KB
testcase_06 AC 233 ms
43,368 KB
testcase_07 AC 234 ms
43,368 KB
testcase_08 AC 237 ms
43,368 KB
testcase_09 AC 238 ms
43,368 KB
testcase_10 AC 238 ms
43,368 KB
testcase_11 AC 237 ms
43,368 KB
testcase_12 AC 237 ms
43,368 KB
testcase_13 AC 180 ms
35,824 KB
testcase_14 AC 102 ms
21,488 KB
testcase_15 AC 100 ms
21,232 KB
testcase_16 AC 148 ms
29,000 KB
testcase_17 AC 171 ms
34,472 KB
testcase_18 AC 190 ms
37,776 KB
testcase_19 AC 171 ms
35,120 KB
testcase_20 AC 173 ms
35,368 KB
testcase_21 AC 201 ms
39,960 KB
testcase_22 AC 168 ms
34,480 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 123 ms
33,880 KB
testcase_29 AC 43 ms
13,344 KB
testcase_30 AC 43 ms
13,516 KB
testcase_31 AC 36 ms
11,892 KB
testcase_32 AC 117 ms
32,120 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

ll op(ll l, ll r){
	return max(l, r);
}

ll e(){
	return -1e14;
}

int main(){
	// ダブリングを行う

	int n, k; cin >> n >> k;
	vector<pair<ll,ll>> x(n);
	rep(i,0,n){
		ll l, r; cin >> l >> r;
		x[i] = pair(l, r);
	}

	sort(x.begin(), x.end(), [](const pair<ll,ll> a, const pair<ll,ll> b){
		return pair(a.second, a.first) < pair(b.second, b.first);
	});
	vector db(20, vector<ll>(n+1, n));

	segtree<ll,op,e> seg(n);

	rep(i,0,n){
		seg.set(i, x[i].first);
	}

	ll g;
	auto f = [&](ll x){
		return x < g;
	};

	rep(i,0,n){
		g = x[i].second;
		int z = seg.max_right(i+1, f);
		db[0][i] = z;
		//cout << i << ' ' << z << endl;
	}

	rep(num,0,19){
		rep(i,0,n){
			db[num+1][i] = db[num][db[num][i]];
		}
	}	

	const ll inf = 1e18;
	ll ans = inf;
	k--;
	rep(i,0,n){
		// kokokara start
		int tar = i;
		rep(j,0,20){
			if (k >> j & 1){
				tar = db[j][tar];
			}
		}
		if (tar < n){
			chmin(ans, x[tar].second - x[i].first);
		}
	}
	if (ans == inf){
		cout << -1 << '\n';
	}else{
		cout << ans << '\n';
	}

}

0