結果

問題 No.2667 Constrained Permutation
ユーザー 沙耶花沙耶花
提出日時 2024-03-08 21:35:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,248 bytes
コンパイル時間 4,916 ms
コンパイル使用メモリ 270,980 KB
実行使用メモリ 33,096 KB
最終ジャッジ日時 2024-03-08 21:35:56
合計ジャッジ時間 11,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 9 ms
6,676 KB
testcase_03 AC 14 ms
6,676 KB
testcase_04 AC 20 ms
6,676 KB
testcase_05 AC 7 ms
6,676 KB
testcase_06 AC 20 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 27 ms
6,676 KB
testcase_09 AC 25 ms
6,676 KB
testcase_10 AC 14 ms
6,676 KB
testcase_11 AC 19 ms
6,676 KB
testcase_12 TLE -
testcase_13 AC 51 ms
6,676 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int check(vector<int> l,vector<int> r,long long k){
	map<int,vector<int>> mp;
	rep(i,l.size()){
		mp[l[i]].push_back(r[i]);
	}
	int n = l.size();
	priority_queue<int,vector<int>,greater<int>> Q;
	rep(i,n){
		int cur = k + i;
		while(mp.size()>0){
			auto it = mp.begin();
			if(it->first <= cur){
				rep(j,it->second.size())Q.push(it->second[j]);
				mp.erase(it);
			}
			else break;
		}
		if(Q.size()==0)return -1;
		if(Q.top()<cur)return 1;
		Q.pop();
	}
	return 0;
	
	
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin>>n;
	vector<int> l(n),r(n);
	rep(i,n)cin>>l[i]>>r[i];
	
	long long ans = 0;
	
	{
		long long ok = -1,ng = 2000000000;
		while(ng-ok>1LL){
			
			long long mid = (ok+ng)/2;
			if(check(l,r,mid)<=0)ok = mid;
			else ng =mid;
		}
		ans += ok;
	}
	
	{
		long long ok = -1,ng = 2000000000;
		while(ng-ok>1LL){
			
			long long mid = (ok+ng)/2;
			if(check(l,r,mid)<=-1)ok = mid;
			else ng =mid;
		}
		ans -= ok;
	}
	cout<<ans<<endl;
	
	
	return 0;
}
0