結果

問題 No.2667 Constrained Permutation
ユーザー kotatsugamekotatsugame
提出日時 2024-03-08 21:28:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 84,848 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-08 21:28:24
合計ジャッジ時間 5,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 39 ms
6,548 KB
testcase_13 AC 3 ms
6,548 KB
testcase_14 AC 108 ms
6,548 KB
testcase_15 AC 63 ms
6,548 KB
testcase_16 AC 44 ms
6,548 KB
testcase_17 AC 15 ms
6,548 KB
testcase_18 AC 117 ms
6,548 KB
testcase_19 AC 109 ms
6,548 KB
testcase_20 AC 116 ms
6,548 KB
testcase_21 AC 80 ms
6,548 KB
testcase_22 AC 82 ms
6,548 KB
testcase_23 AC 81 ms
6,548 KB
testcase_24 AC 48 ms
6,548 KB
testcase_25 AC 94 ms
6,548 KB
testcase_26 AC 116 ms
6,548 KB
testcase_27 AC 114 ms
6,548 KB
testcase_28 AC 51 ms
6,548 KB
testcase_29 AC 49 ms
6,548 KB
testcase_30 AC 56 ms
6,548 KB
testcase_31 AC 34 ms
6,548 KB
testcase_32 AC 9 ms
6,548 KB
testcase_33 AC 70 ms
6,548 KB
testcase_34 AC 37 ms
6,548 KB
testcase_35 AC 44 ms
6,548 KB
testcase_36 AC 43 ms
6,548 KB
testcase_37 AC 46 ms
6,548 KB
testcase_38 AC 68 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 37 ms
6,548 KB
testcase_41 AC 59 ms
6,548 KB
testcase_42 AC 63 ms
6,548 KB
testcase_43 AC 89 ms
6,548 KB
testcase_44 AC 35 ms
6,548 KB
testcase_45 AC 3 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;cin>>N;
	vector<pair<int,int> >LR(N);
	for(int i=0;i<N;i++)cin>>LR[i].first>>LR[i].second;
	sort(LR.begin(),LR.end());
	int lk=-2e9;
	for(int i=0;i<N;i++)
	{
		int l=LR[i].first;
		//l<=k+i+1 <=> l-i-1<=k
		lk=max(lk,l-i-1);
	}
	{
		priority_queue<int,vector<int>,greater<int> >Q;
		int pi=0;
		for(int i=1;i<=N;i++)
		{
			while(pi<N&&LR[pi].first-lk<=i)
			{
				Q.push(LR[pi++].second-lk);
			}
			if(Q.empty()||Q.top()<i)
			{
				cout<<0<<endl;
				return 0;
			}
			Q.pop();
		}
	}
	sort(LR.begin(),LR.end(),[](pair<int,int>l,pair<int,int>r){return l.second<r.second;});
	int rk=2e9;
	for(int i=0;i<N;i++)
	{
		int r=LR[i].second;
		//k+i+1<=r <=> k<=r-i-1
		rk=min(rk,r-i-1);
	}
	cout<<rk-lk+1<<endl;
}
0