結果

問題 No.2667 Constrained Permutation
ユーザー inksamuraiinksamurai
提出日時 2024-03-08 23:50:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 215,676 KB
実行使用メモリ 18,936 KB
最終ジャッジ日時 2024-03-08 23:50:24
合計ジャッジ時間 6,813 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 48 ms
9,060 KB
testcase_29 AC 46 ms
8,796 KB
testcase_30 AC 55 ms
9,508 KB
testcase_31 AC 33 ms
7,040 KB
testcase_32 AC 8 ms
6,676 KB
testcase_33 AC 93 ms
14,888 KB
testcase_34 AC 53 ms
9,660 KB
testcase_35 AC 59 ms
10,628 KB
testcase_36 AC 57 ms
10,260 KB
testcase_37 AC 65 ms
11,136 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 36 ms
7,352 KB
testcase_41 AC 58 ms
9,716 KB
testcase_42 AC 168 ms
14,424 KB
testcase_43 AC 255 ms
18,936 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 k=a[0].fi-1;
	if(!af(k)){
		k=a[1].fi-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