Submission #1319677

#TimeUsernameProblemLanguageResultExecution timeMemory
1319677PieArmyCultivation (JOI17_cultivation)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
#define endl '\n'
using namespace std;
#define mid ((left+right)>>1)
#define int ll
int h,w,n;
pair<int,int>arr[323];
vector<int>lens;
set<pair<int,int>>st;
map<int,vector<int>>mp;
int ans=2e9;

signed main(){
	ios_base::sync_with_stdio(23^23);cin.tie(0);
	cin>>h>>w>>n;
	{
		int a=h,b=w;
		for(int i=1;i<=n;i++){
			cin>>arr[i].fr>>arr[i].sc;
			a=min(a,arr[i].fr-1);
			b=min(b,arr[i].sc-1);
		}
		for(int i=1;i<=n;i++){
			arr[i].fr-=a;
			arr[i].sc-=b;
		}
	}
	sort(arr+1,arr+n+1,[&](const auto&x,const auto&y){
		return x.sc<y.sc;
	});
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			lens.pb(max(0,arr[j].sc-arr[i].sc-1));
		}
		lens.pb(w-arr[i].sc);
	}
	sort(lens.begin(),lens.end());
	lens.resize(unique(lens.begin(),lens.end())-lens.begin());
	for(int k:lens){
		mp.clear();
		st.clear();
		bool valid=true;
		for(int i=2;i<=n;i++){
			if(arr[i-1].sc+k+1<arr[i].sc)valid=false;
		}
		if(arr[n].sc+k<w)valid=false;
		if(!valid)continue;
		for(int i=1;i<=n;i++){
			mp[arr[i].sc].pb(i);
			mp[arr[i].sc+k+1].pb(-i);
		}
		int a=0,b=0,sum=0;
		for(auto&[x,v]:mp){
			if(x>w)break;
			for(int y:v){
				if(y<0){
					y*=-1;
					st.erase(st.find({arr[y].fr,y}));
				}
				else{
					st.insert({arr[y].fr,y});
				}
			}
			for(int y:v){
				if(y<0){
					y*=-1;
					auto ust=st.upper_bound({arr[y].fr,y});
					auto alt=st.lower_bound({arr[y].fr,y});
					if(alt==st.begin()){
						a=max(a,ust->fr-1);
					}
					if(ust==st.end()){
						alt--;
						b=max(b,h-alt->fr);
					}
					else if(alt!=st.begin()){
						alt--;
						sum=max(sum,ust->fr-alt->fr-1);
					}
				}
				else{
					auto ust=st.upper_bound({arr[y].fr,y});
					auto alt=st.lower_bound({arr[y].fr,y});
					if(ust==st.end()){
						b=max(b,h-arr[y].fr);
					}
					else{
						sum=max(sum,ust->fr-arr[y].fr-1);
					}
					if(alt==st.begin()){
						a=max(a,arr[y].fr-1);
					}
					else{
						alt--;
						sum=max(sum,arr[y].fr-alt->fr-1);
					}
				}
			}
		}
		ans=min(ans,k+max(sum,a+b));
	}
	cout<<ans<<endl;
}

Compilation message (stderr)

cultivation.cpp: In function 'int main()':
cultivation.cpp:37:36: error: no matching function for call to 'max(int, long long int)'
   37 |                         lens.pb(max(0,arr[j].sc-arr[i].sc-1));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from cultivation.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
cultivation.cpp:37:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |                         lens.pb(max(0,arr[j].sc-arr[i].sc-1));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
cultivation.cpp:37:36: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |                         lens.pb(max(0,arr[j].sc-arr[i].sc-1));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
cultivation.cpp:37:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |                         lens.pb(max(0,arr[j].sc-arr[i].sc-1));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
cultivation.cpp:37:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   37 |                         lens.pb(max(0,arr[j].sc-arr[i].sc-1));
      |                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~