QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643007#360. CultivationSimonLJK0 0ms0kbC++173.3kb2024-10-15 17:50:422024-10-15 17:50:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 17:50:43]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-15 17:50:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp(a,b) make_pair(a,b)
const int N=309;
const int inf=2e9+10;
int r,c,n,ans;
struct node{
	int x,y;
	bool operator <(const node&A)const{
		return x<A.x;
	}
}p[N];
int L[N][N],R[N][N],Len[N][N];
multiset<int> ms;
multiset<int> ::iterator it,it1,it2;
void init(){
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++) ms.insert(p[j].y);
		L[i][n]=(*ms.begin())-1;
		it=ms.end(); it--; R[i][n]=c-(*it);
		it1=ms.begin(); it2=ms.begin(); it2++;
		for(;it2!=ms.end();it1++,it2++)
			Len[i][n]=max(Len[i][n],(*it2)-(*it1)-1);
		for(int j=n;j>i;j--){
			Len[i][j-1]=Len[i][j];
			it=ms.find(p[j].y);
			if(it!=ms.begin()){
				it--; it1=it;
				it++; it++; it2=it;
				if(it2!=ms.end())
					Len[i][j-1]=max(Len[i][j-1],(*it2)-(*it1)-1);
			}
			ms.erase(ms.find(p[j].y));
			it=ms.begin(); L[i][j-1]=(*it)-1;
			it=ms.end(); it--; R[i][j-1]=c-(*it);
			Len[i][j-1]=max(Len[i][j-1],L[i][j-1]+R[i][j-1]);
		}
		ms.clear();
	}
	return;
}
list<pair<int,int> > ql,qr,qlen;
int solve(int len){//鎷撳睍len,闀垮害len+1
	ql.push_back(mp(inf,0)); qr.push_back(mp(inf,0)); qlen.push_back(mp(inf,0));
	int res=r+c;
	int pi=0,po=0;
	int ln=1,rn=0,nxt,now;
	p[n+1]=(node){inf,inf};
	while(pi<n||po<n){
		nxt=min(p[pi+1].x,p[po+1].x+len+1/*outside*/);
		while(pi<n&&p[pi+1].x==nxt){ rn++; pi++; }
		while(po<n&&p[po+1].x+len+1==nxt){ ln++; po++; }
		now=nxt; nxt=min(p[pi+1].x,p[po+1].x+len+1/*outside*/);
		if(pi==n&&po==n) break;
		nxt--;
		while(!ql.empty()&&ql.back().first<=L[ln][rn]) ql.pop_back();
		ql.push_back(mp(L[ln][rn],nxt));
		while(!qr.empty()&&qr.back().first<=R[ln][rn]) qr.pop_back();
		qr.push_back(mp(R[ln][rn],nxt));
		while(!qlen.empty()&&qlen.back().first<=Len[ln][rn]) qlen.pop_back();
		qlen.push_back(mp(Len[ln][rn],nxt));
		if(nxt>=r+p[1].x-1){
			while(ql.front().second<=nxt-r) ql.pop_front();
			while(qr.front().second<=nxt-r) qr.pop_front();
			while(qlen.front().second<=nxt-r) qlen.pop_front();
			res=min(res,max(ql.front().first+qr.front().first,qlen.front().first));
		}
	}
	ql.clear(); qr.clear(); qlen.clear();
	return res;
}
vector<int> vx,vec;
signed main(){
	freopen("cheat6.in","r",stdin);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>r>>c>>n; ans=r+c-2;
	for(int i=1;i<=n;i++){
		cin>>p[i].x>>p[i].y;
		vx.push_back(p[i].x);
	}
	sort(p+1,p+n+1);
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	int l=vx[0]-1,rr=r-vx.back(); int mx=l+rr;
	for(int i=1;i<vx.size();i++) mx=max(mx,vx[i]-vx[i-1]-1);
	vec.push_back(mx);
	for(int i=0;i<vx.size();i++)
		for(int j=i+1;j<vx.size();j++)
			vec.push_back(vx[j]-vx[i]),vec.push_back(vx[j]-vx[i]+1),vec.push_back(r-vx[j]+vx[i]-1),vec.push_back(r-vx[j]+vx[i]),vec.push_back(r+vx[j]-vx[i]-1),vec.push_back(r+vx[j]-vx[i]);
//	for(int i=0;i<vx.size();i++)
//		vec.push_back(vx[i]-1),vec.push_back(r-vx[i]);
	sort(vec.begin(),vec.end());
	for(int i=0;i<vec.size();i++) if(vec[i]<mx) vec[i]=mx;
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	cerr<<1<<endl;
	init();
//	if(c==1000000000){
//		cout<<Len[1][n]<<endl;
//		return 0;
//	}
	cerr<<2<<endl;
	for(int len:vec){
//	for(int len=mx;len<=r;len++)
		ans=min(ans,solve(len)+len);
		cerr<<len<<endl;
	}
	cout<<ans;
	return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

2 4
2
1 1
1 4

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #45:

score: 0
Runtime Error

input:

1000000000 1000000000
17
822413671 70423910
260075513 431043546
300945721 793553248
142848049 163787897
392462410 831950868
699005697 111397300
444396260 130450496
642691616 595456084
467968916 463598810
159764248 611476406
929313754 539645102
365153650 964108073
906780716 373514044
970118116 655138...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%