結果

問題 No.2667 Constrained Permutation
ユーザー inksamuraiinksamurai
提出日時 2024-03-10 00:57:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,610 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 215,772 KB
実行使用メモリ 22,512 KB
最終ジャッジ日時 2024-03-10 00:57:20
合計ジャッジ時間 11,146 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 7 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 143 ms
9,216 KB
testcase_13 AC 6 ms
6,676 KB
testcase_14 AC 464 ms
21,024 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 66 ms
6,676 KB
testcase_18 AC 494 ms
22,004 KB
testcase_19 AC 581 ms
15,728 KB
testcase_20 AC 671 ms
18,544 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 209 ms
11,788 KB
testcase_25 AC 525 ms
19,420 KB
testcase_26 AC 715 ms
22,512 KB
testcase_27 AC 459 ms
22,512 KB
testcase_28 AC 50 ms
9,060 KB
testcase_29 AC 46 ms
8,756 KB
testcase_30 AC 53 ms
9,508 KB
testcase_31 AC 33 ms
7,040 KB
testcase_32 AC 8 ms
6,676 KB
testcase_33 AC 88 ms
14,796 KB
testcase_34 AC 45 ms
9,600 KB
testcase_35 AC 55 ms
10,624 KB
testcase_36 AC 53 ms
10,240 KB
testcase_37 AC 54 ms
11,136 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 43 ms
9,216 KB
testcase_41 AC 67 ms
12,788 KB
testcase_42 AC 275 ms
14,384 KB
testcase_43 AC 287 ms
18,796 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int) a.size())
#define vec(...) vector<__VA_ARGS__>
#define _3TpP2FO ios::sync_with_stdio(0),cin.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}

void slv(){
	int n;
	cin>>n;

	vec(pii) a(n);
	rep(i,n){
		cin>>a[i].fi>>a[i].se;
	}
	sort(all(a));

	// mi - k = 1
	// k = mi - 1
	auto af=[&](int k)->int{
		vec(vi) adqry(n+1);
		rep(i,n){
			auto [l,r]=a[i];
			l-=k,r-=k;
			if(r<0){
				return 0;
			}
			if(l>n){
				return 0;
			}
			l=max(l,1ll);
			r=min(r,n);
			if(l>r){
				return 0;
			}
			adqry[l].pb(r);
		}
		multiset<int> mst;
		rng(i,1,n+1){
			while(sz(mst) and *mst.begin()<i){
				mst.erase(mst.begin());
			}
			for(auto r:adqry[i]){
				mst.insert(r);
			}
			if(!sz(mst)){
				return 0;
			}
			auto it=mst.begin();
			mst.erase(it);
		}
		return 1;
	};
	int mi=1e9;
	rep(i,n){
		mi=min(mi,a[i].se);
	}
	int k=mi-1;
	if(!af(k)){
		cout<<"0\n";
		return;
	}

	int opt_r=k;
	{
		int l=k,r=1e10;
		while(l<=r){
			int m=(l+r)/2;
			if(af(m)) opt_r=m,l=m+1;
			else r=m-1;
		}
	}
	int opt_l=k;
	{
		int l=-1e10,r=k;
		while(l<=r){
			int m=(l+r)/2;
			if(af(m)) opt_l=m,r=m-1;
			else l=m+1;
		}
	}
	print(opt_r-opt_l+1);
}

signed main(){
_3TpP2FO;
	slv();
}
0