QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478259#142. 平面最近点对Williamxzh#0 5ms6588kbC++231.6kb2024-07-14 19:43:542024-07-14 19:43:54

Judging History

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

  • [2024-07-14 19:43:54]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:6588kb
  • [2024-07-14 19:43:54]
  • 提交

answer

#include <bits/stdc++.h>
#define il inline
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=2e6+5,inf=2e9;const ll oo=4e18;
int n,B,cnt;pii a[N];ll ans;
il ll dis(pii x,pii y){return 1ll*(x.fi-y.fi)*(x.fi-y.fi)+1ll*(x.se-y.se)*(x.se-y.se);}
int dx[9]={0,0,1,1,1,0,-1,-1,-1};
int dy[9]={0,1,1,0,-1,-1,-1,0,1};
unordered_map<ll,int> mp;
vector<pii> e[N];
il ll id(int x,int y){return 1ll*inf*(x/B)+1ll*(y/B);}
il void add(int i){
    ll w=id(a[i].fi,a[i].se);
    if(!mp.count(w)) mp[w]=++cnt;
    e[mp[w]].push_back({a[i].fi,a[i].se});
}
int x,y,z,u,v,w;ll mi;ll p,q,r;
int main(){
    //freopen("P1429_1.in","r",stdin);
    mt19937 rnd(time(0));
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d%d",&a[i].fi,&a[i].se);
    shuffle(a+1,a+1+n,rnd);
    ans=dis(a[1],a[2]),B=sqrtl(ans)+1,add(1),add(2);
    for(int i=3;i<=n;++i){
        mi=oo,u=a[i].fi/B,v=a[i].se/B;
        for(int j=0;j<9;++j){
            if(u+dx[j]<0 || v+dy[j]<0) continue;
            w=mp[1ll*(u+dx[j])*inf+(v+dy[j])];if(!w) continue;
            for(pii it:e[w]) mi=min(mi,dis(a[i],it));
        }
        if(mi>=ans){add(i);continue;}
        for(int j=1;j<=cnt;++j) e[j].clear();mp.clear();cnt=0;
        ans=mi,B=sqrtl(ans)+1;
        for(int j=1;j<=i;++j){
            p=1ll*(a[j].fi/B)*inf+(a[j].se/B),u=mp[p];if(!u) mp[p]=++cnt,u=cnt;
            e[u].push_back({a[j].fi,a[j].se});
        }
        //if(clock()>1900000){double dd=sqrtl(ans);printf("%.15lf",dd);exit(0);}
    }
    double dd=sqrtl(ans);
    printf("%.15lf",dd);
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 6588kb

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:

6.403124237432849

result:

wrong answer 1st numbers differ - expected: '2.8284271', found: '6.4031242', error = '1.2638463'

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%