QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385318#5809. Min Perimeterzjy000120 ✓8168ms25104kbC++172.4kb2024-04-10 17:37:392024-04-10 17:37:39

Judging History

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

  • [2024-04-10 17:37:39]
  • 评测
  • 测评结果:20
  • 用时:8168ms
  • 内存:25104kb
  • [2024-04-10 17:37:39]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb double
#define uLL unsigned long long
using namespace std;
const int N=1e6+5;
const ldb INF=1e10;
int n;ldb ans,D[N];pair<int,int>A[N];
inline ldb dist(const int&x,const int&y){
    const auto [xx,xy]=A[x];const auto [yx,yy]=A[y];
    return sqrt(1ll*(xx-yx)*(xx-yx)+1ll*(xy-yy)*(xy-yy));
}
inline bool cmp(const pair<int,int>&x,const pair<int,int>&y){
    return x.second<y.second;
}
inline void solve(int l,int r){
    if(r-l<2){
        if(l<r&&!cmp(A[l],A[r]))swap(A[l],A[r]);
        return;
    }
    const int mid=(l+r)>>1;
    solve(l,mid),solve(mid+1,r);
    const int lx=max_element(A+l,A+mid+1)->first;
    const int rx=min_element(A+mid+1,A+r+1)->first;
    vector<int>S;
    for(int i=l,lp=mid+1,rp=mid+1;i<=mid;++i)
        if(rx-A[i].first<ans){
            for(;rp<=r&&A[rp].second-A[i].second<ans;++rp)
                if(A[rp].first-lx<ans)S.emplace_back(rp);
            for(;lp<rp&&A[i].second-A[lp].second>=ans;++lp);
            vector<int>T;T.reserve(10);
            for(auto j:S)if(j>=lp&&A[j].first-lx<ans)
                T.emplace_back(j),D[j]=dist(i,j);
            S=move(T);
            for(auto j:S)if(D[j]<ans)for(auto k:S)
                if(k<j){if(D[k]<ans)ans=min(ans,(D[j]+D[k]+dist(j,k))/2);}
                else break;
        }
    S.clear();
    for(int i=mid+1,lp=l,rp=l;i<=r;++i)
        if(A[i].first-lx<ans){
            for(;rp<=mid&&A[rp].second-A[i].second<ans;++rp)
                if(rx-A[rp].first<ans)S.emplace_back(rp);
            for(;lp<rp&&A[i].second-A[lp].second>=ans;++lp);
            vector<int>T;T.reserve(10);
            for(auto j:S)if(j>=lp&&rx-A[j].first<ans)
                T.emplace_back(j),D[j]=dist(i,j);
            S=move(T);
            for(auto j:S)if(D[j]<ans)for(auto k:S)
                if(k<j){if(D[k]<ans)ans=min(ans,(D[j]+D[k]+dist(j,k))/2);}
                else break;
        }
    inplace_merge(A+l,A+mid+1,A+r+1,cmp);
}
inline void MAIN(){
    cin>>n,ans=INF;
    for(int i=1;i<=n;++i)
        cin>>A[i].first>>A[i].second;
    sort(A+1,A+n+1),solve(1,n);
    cout<<fixed<<setprecision(9)<<ans*2<<'\n';
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int t=1;cin>>t;for(int _=1;t--;++_)
        cout<<"Case #"<<_<<": ",MAIN();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 56ms
memory: 6112kb

input:

15
3
2 6
7 0
3 0
3
713 269
371 79
455 421
3
91983245 637281504
756917015 312173515
869576338 436726680
10000
14761642 78236002
9047458 47951098
5238002 27761162
476182 2523742
1428546 7571226
26190010 138805810
21904372 116092132
18094916 95902196
43332562 229660522
55237112 292754072
52380020 27761...

output:

Case #1: 17.893012206
Case #2: 1042.844834964
Case #3: 1711142102.791327000
Case #4: 90912.296374033
Case #5: 3.414213562
Case #6: 26.153830342
Case #7: 1701.012681096
Case #8: 2865438.191993871
Case #9: 2020088.337226320
Case #10: 1792106.037292071
Case #11: 2019352.542909729
Case #12: 2530195.7280...

result:

ok correct! (15 test cases)

Subtask #2:

score: 15
Accepted

Test #2:

score: 15
Accepted
time: 8168ms
memory: 25104kb

input:

15
3
501691275 344354353
167768963 536043860
249445040 557426549
4
1000000000 0
0 0
1000000000 1000000000
0 1000000000
1000000
138925776 669369648
61257680 295150640
170762328 822763944
55483472 267329456
97736936 470914328
84041848 404928904
18463588 88960924
124429360 599523280
95066048 458045504
...

output:

Case #1: 799653579.133089781
Case #2: 3414213562.373095036
Case #3: 866.071590574
Case #4: 62459.895369637
Case #5: 59141.918358932
Case #6: 898195.090968268
Case #7: 1707085.769986785
Case #8: 1686.226798258
Case #9: 1686.603545972
Case #10: 6806.665583936
Case #11: 1907363.078325002
Case #12: 1798...

result:

ok correct! (15 test cases)

Extra Test:

score: 0
Extra Test Passed