QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642961#360. CultivationSimonLJK0 2ms5872kbC++172.9kb2024-10-15 17:22:232024-10-15 17:22:23

Judging History

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

  • [2024-10-15 17:22:23]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:5872kb
  • [2024-10-15 17:22:23]
  • 提交

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;
}
int solve(int len){//鎷撳睍len,闀垮害len+1
	list<pair<int,int> > ql,qr,qlen;
	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){
			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));
		}
	}
	return res;
}
vector<int> vx,vec;
signed main(){
	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(r-vx[j]+vx[i]-1);
	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());
	init();
	for(int len:vec)
		ans=min(ans,solve(len)+len);
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 3608kb

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3540kb

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3808kb

input:

3 3
3
1 2
1 3
3 3

output:

3

result:

ok single line: '3'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3580kb

input:

2 2
1
1 2

output:

2

result:

ok single line: '2'

Test #5:

score: 5
Accepted
time: 0ms
memory: 3640kb

input:

4 4
10
4 2
2 3
2 4
4 1
1 2
2 1
4 3
3 3
3 1
1 4

output:

2

result:

ok single line: '2'

Test #6:

score: 5
Accepted
time: 0ms
memory: 3756kb

input:

4 4
1
4 1

output:

6

result:

ok single line: '6'

Test #7:

score: 5
Accepted
time: 0ms
memory: 3592kb

input:

4 4
3
2 2
3 3
1 4

output:

5

result:

ok single line: '5'

Test #8:

score: 5
Accepted
time: 0ms
memory: 3896kb

input:

4 4
15
4 3
2 4
4 4
4 1
3 3
1 2
3 1
2 1
3 4
3 2
4 2
2 3
1 3
2 2
1 4

output:

1

result:

ok single line: '1'

Test #9:

score: 5
Accepted
time: 1ms
memory: 5640kb

input:

4 3
3
2 1
2 3
4 1

output:

3

result:

ok single line: '3'

Test #10:

score: 5
Accepted
time: 0ms
memory: 3800kb

input:

4 4
2
3 4
2 4

output:

5

result:

ok single line: '5'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3608kb

input:

2 4
1
1 2

output:

4

result:

ok single line: '4'

Test #12:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

3 3
4
2 1
1 1
3 2
3 1

output:

2

result:

ok single line: '2'

Test #13:

score: 5
Accepted
time: 1ms
memory: 5872kb

input:

3 4
3
1 4
3 3
3 4

output:

4

result:

ok single line: '4'

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3492kb

input:

3 3
2
2 1
3 3

output:

3

result:

wrong answer 1st lines differ - expected: '4', found: '3'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #45:

score: 30
Accepted
time: 1ms
memory: 3700kb

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:

852626202

result:

ok single line: '852626202'

Test #46:

score: 30
Accepted
time: 2ms
memory: 3728kb

input:

1000000000 1000000000
24
382358372 812500277
617637090 687506454
441176760 562497727
382346048 687504690
205880053 312504652
794110577 62497634
264714161 937490675
970587944 812502893
617647581 62504110
852944701 812498007
88227293 187492617
558814156 687495577
29403236 812494493
911761865 187491781...

output:

904419459

result:

ok single line: '904419459'

Test #47:

score: 30
Accepted
time: 2ms
memory: 4016kb

input:

1000000000 1000000000
25
59999964 299999989
740000035 100000111
139999972 499999797
740000159 899999809
940000104 899999905
459999870 299999853
139999925 899999750
260000183 300000150
260000200 699999915
940000072 99999821
340000223 900000130
739999776 499999813
59999984 700000029
539999767 90000023...

output:

480000793

result:

ok single line: '480000793'

Test #48:

score: 0
Wrong Answer
time: 0ms
memory: 3732kb

input:

1000000000 1000000000
25
496770868 499466029
150245306 140351260
443861207 442170127
915815913 907024280
592352731 580300173
614771420 602707761
545759771 564678204
790963611 795646738
466306333 474998682
700037062 710428701
326403486 341417980
13108429 18468915
296795338 282907012
207909366 2192548...

output:

1967642758

result:

wrong answer 1st lines differ - expected: '1967193239', found: '1967642758'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%