結果

問題 No.2543 Many Meetings
ユーザー 沙耶花沙耶花
提出日時 2023-11-24 21:41:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,152 bytes
コンパイル時間 6,515 ms
コンパイル使用メモリ 267,872 KB
実行使用メモリ 22,584 KB
最終ジャッジ日時 2023-11-24 21:41:51
合計ジャッジ時間 11,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 186 ms
6,676 KB
testcase_04 AC 187 ms
6,676 KB
testcase_05 AC 188 ms
6,676 KB
testcase_06 AC 187 ms
6,676 KB
testcase_07 AC 187 ms
6,676 KB
testcase_08 AC 184 ms
6,676 KB
testcase_09 AC 182 ms
6,676 KB
testcase_10 AC 182 ms
6,676 KB
testcase_11 AC 184 ms
6,676 KB
testcase_12 AC 183 ms
6,676 KB
testcase_13 AC 158 ms
8,780 KB
testcase_14 AC 92 ms
7,404 KB
testcase_15 AC 92 ms
7,400 KB
testcase_16 AC 133 ms
8,360 KB
testcase_17 AC 152 ms
8,640 KB
testcase_18 AC 210 ms
21,340 KB
testcase_19 AC 193 ms
19,780 KB
testcase_20 AC 193 ms
19,836 KB
testcase_21 AC 224 ms
22,584 KB
testcase_22 AC 189 ms
19,468 KB
testcase_23 AC 2 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 3 ms
6,676 KB
testcase_28 AC 80 ms
6,676 KB
testcase_29 AC 28 ms
6,676 KB
testcase_30 AC 28 ms
6,676 KB
testcase_31 AC 24 ms
6,676 KB
testcase_32 AC 75 ms
6,676 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 <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<pair<int,int>> lr(N);
	rep(i,N){
		cin>>lr[i].first>>lr[i].second;
	}
	sort(lr.begin(),lr.end());
	
	{
		vector<pair<int,int>> nl;
		rep(i,N){
			while(nl.size()>0 && nl.back().second>=lr[i].second)nl.pop_back();
			nl.push_back(lr[i]);
		}
		swap(lr,nl);
		N = lr.size();
	}
	
	vector nxt(N,vector<int>(18,N));
	rep(i,N){
		int d = distance(lr.begin(),lower_bound(lr.begin(),lr.end(),make_pair(lr[i].second,-1)));
		nxt[i][0] = d;
	}
	for(int i=1;i<18;i++){
		rep(j,N){
			if(nxt[j][i-1]==N)nxt[j][i] = N;
			else nxt[j][i] = nxt[nxt[j][i-1]][i-1];
		}
	}
	
	int ans = Inf32;
	K--;
	rep(i,N){
		//cout<<lr[i].first<<' '<<lr[i].second<<endl;
		int cur = i;
		rep(j,18){
			if((K>>j)&1){
				if(cur!=N)cur = nxt[cur][j];
			}
		}
		if(cur!=N){
			ans = min(ans,lr[cur].second - lr[i].first);
		}
	}
	if(ans==Inf32)ans = -1;
	cout<<ans<<endl;
	
	return 0;
}
0