QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125345#142. 平面最近点对NOI_AK_ME#0 2ms7860kbC++231.3kb2023-07-16 16:06:382023-07-16 16:06:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 16:06:42]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:7860kb
  • [2023-07-16 16:06:38]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct Point{int x,y;}a[2000000],tmp[2000000];
int n,b[2000000];
const long long inf=5e18;
long long sqr(int x){return (long long)x*x;}
long long dis(int l,int r){return sqr(a[l].x-a[r].x)+sqr(a[l].y-a[r].y);}
int cmp(const Point &a,const Point &b){return a.x==b.x?a.y<b.y:a.x<b.x;}
void merge(int l,int r)
{
	int mid=(l+r)>>1,i=l,j=mid+1;//归并
	for(int k=l;k<=r;k++)
	{
		if(i<=mid&&(j>r||a[i].y<a[j].y))tmp[k]=a[i++];
		else tmp[k]=a[j++];
	}
	for(int i=l;i<=r;i++)a[i]=tmp[i];
}
long long solve(int l,int r)
{
	if(l>=r)return inf;
	if(l+1==r){if(a[l].y>a[r].y)swap(a[l],a[r]);return dis(l,r);}
	int mid=(l+r)>>1,t=a[mid].x,cnt=0;//重新排序后中位数就乱了,需要记下来
	long long d=min(solve(l,mid),solve(mid+1,r));
	merge(l,r);
	for(int i=l;i<=r;i++)
		if(sqr(a[i].x-t)<d)//两边平方的技巧
			b[++cnt]=i;//区间内的拉出来处理
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt&&sqr(a[b[j]].y-a[b[i]].y)<d;j++)
			d=min(d,dis(b[j],b[i]));
	return d;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	printf("%.4lf",sqrt(solve(1,n)));
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7860kb

input:

2933
19320 28055
2053 27470
14635 1378
27582 9822
28729 107
22351 3093
17670 379
23901 4686
27182 12261
19443 8467
24208 20283
10763 10584
25953 28380
28290 27394
19572 14769
4024 12401
23295 3267
26949 176
13416 4517
23856 15413
26260 18957
18275 24409
999 3873
28202 14686
25446 2822
24009 8949
114...

output:

2.8284

result:

wrong answer 1st numbers differ - expected: '2.8284271', found: '2.8284000', error = '0.0000096'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%