QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96533#360. Cultivationtricyzhkx0 2ms3776kbC++142.5kb2023-04-14 10:31:532023-04-14 10:31:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-14 10:31:57]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3776kb
  • [2023-04-14 10:31:53]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
void chkmax(int &a,int b){a=max(a,b);}
void chkmin(int &a,int b){a=min(a,b);}
struct Point
{
	int x,y;
	bool operator<(const Point &a)const{return x<a.x;}
}a[310];
int H,W,n,p[610],L[310],R[310],pre[610],mny[610],mxy[610],mxd[610],len[100010],miny[310][310],maxy[310][310],maxd[310][310];
ll ans=1e18;
multiset<int> st;
struct Que
{
	int le,ri;
	pii que[610];
	void clear(){le=ri=0;}
	void push(pii x)
	{
		while(le<ri && que[ri-1]<x) ri--;
		que[ri++]=x;
	}
	void pop(int x){while(le<ri && que[le].second<x) le++;}
	bool empty(){return le>=ri;}
	int top(){return que[le].first;}
}Q1,Q2,Q3;
void solve(int len)
{
	int t1=0,t2=0;
	for(int i=1;i<=n;i++) L[i]=a[i].x,R[i]=L[i]+len;
	for(int i=1;i<=n;i++) p[++t1]=L[i];
	t2=t1;
	for(int i=1;i<=n;i++) p[++t2]=R[i];
	inplace_merge(p+1,p+t1+1,p+t2+1);
	t2=unique(p+1,p+t2+1)-p-1;
	for(int i=1,j=1,k=1;i<=n;i++)
	{
		for(;p[j]<L[i];j++);
		for(;p[k]<R[i];k++);
		L[i]=j;R[i]=k;
	}
	for(int i=1,j=1,k=0;i<=t2;i++)
	{
		for(;j<=n && R[j]<=i;j++);
		for(;k<n && L[k+1]<=i;k++);
		pre[i]=pre[i-1];
		if(j>k){pre[i]++;continue;}
		mny[i]=miny[j][k];mxy[i]=maxy[j][k];mxd[i]=maxd[j][k];
	}
	Q1.clear();Q2.clear();Q3.clear();
	for(int i=1,j=1;i<R[1];i++)
	{
		for(;j<=t2 && p[j]<=p[i]+H-1;j++)
			if(pre[j]==pre[j-1])
				Q1.push({mny[j],j}),Q2.push({mxy[j],j}),Q3.push({mxd[j],j});
		Q1.pop(i);Q2.pop(i);Q3.pop(i);
		if(pre[j-1]==pre[i-1] && !Q1.empty() && !Q2.empty() && !Q3.empty())
			ans=min(ans,(ll)len+max(Q1.top()+W-Q2.top(),Q3.top())-2);
	}
}
int main()
{
	cin>>H>>W>>n;
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		miny[i][i-1]=1e9;maxy[i][i-1]=-1e9;
		st.clear();st.insert(0);st.insert(W+1);
		for(int j=i;j<=n;j++)
		{
			st.insert(a[j].y);
			miny[i][j]=min(miny[i][j-1],a[j].y);
			maxy[i][j]=max(maxy[i][j-1],a[j].y);
		}
		for(auto it=st.begin();it!=st.end();it++)
			if(next(it)!=st.end()) chkmax(maxd[i][n],*next(it)-*it);
		for(int j=n;j>i;j--)
		{
			auto it=st.find(a[j].y);
			it=st.erase(it);
			maxd[i][j-1]=max(maxd[i][j],*it-*prev(it));
		}
	}
	int tot=0;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			if(a[i].x<a[j].x) len[++tot]=a[j].x-a[i].x;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			len[++tot]=a[i].x+H-a[j].x;
	sort(len+1,len+tot+1);
	tot=unique(len+1,len+tot+1)-len-1;
	for(int i=1;i<=tot;i++) solve(len[i]);
	cout<<ans<<endl;
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 2ms
memory: 3736kb

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3772kb

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3628kb

input:

3 3
3
1 2
1 3
3 3

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

2 2
1
1 2

output:

2

result:

ok single line: '2'

Test #5:

score: -5
Wrong Answer
time: 2ms
memory: 3776kb

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:

1

result:

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

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: 0
Wrong Answer
time: 2ms
memory: 3564kb

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:

770680920

result:

wrong answer 1st lines differ - expected: '852626202', found: '770680920'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%