QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536680 | #5809. Min Perimeter | zhicheng | 0 | 0ms | 0kb | C++14 | 1.6kb | 2024-08-29 15:39:29 | 2024-08-29 15:39:30 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
struct s{
int x,y;
bool operator<(s b){
return x<b.x;
}
}p[N],x[N],y[N];
double dist(s a,s b){
return sqrt(1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y));
}
double solve(int l,int r){
int mid=(l+r)>>1,cntx=0,cnty=0,posl=1,posr=1;
double px=(p[mid].x+p[mid+1].x)/2.0,delta,ans;
if(l==r){
return 1e18;
}
ans=delta=min(solve(l,mid),solve(mid+1,r));
for(int i=l;i<=mid;i++){
if(px-p[i].x<=delta/2){
x[++cntx]=p[i];
}
}
for(int i=mid+1;i<=r;i++){
if(p[i].x-px<=delta/2){
y[++cnty]=p[i];
}
}
sort(x+1,x+cntx+1,[](s a,s b){return a.y<b.y;});
sort(y+1,y+cnty+1,[](s a,s b){return a.y<b.y;});
for(int i=1;i<=cntx;i++){
while(posl<=cnty&&x[i].y-y[posl].y>delta/2){
posl++;
}
while(posr+1<=cnty&&y[posr+1].y-x[i].y<=delta/2){
posr++;
}
for(int j=posl;j<=posr;j++){
for(int k=j+1;k<=posr;k++){
ans=min(ans,dist(x[i],y[j])+dist(x[i],y[k])+dist(y[j],y[k]));
}
}
}
swap(x,y);
swap(cntx,cnty);
posl=posr=1;
for(int i=1;i<=cntx;i++){
while(posl<=cnty&&x[i].y-y[posl].y>delta/2){
posl++;
}
while(posr+1<=cnty&&y[posr+1].y-x[i].y<=delta/2){
posr++;
}
for(int j=posl;j<=posr;j++){
for(int k=j+1;k<=posr;k++){
ans=min(ans,dist(x[i],y[j])+dist(x[i],y[k])+dist(y[j],y[k]));
}
}
}
return ans;
}
int main(){
int t,n;
scanf("%d",&t);
for(int tt=1;tt<=t;tt++){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&p[i].x,&p[i].y);
}
sort(p+1,p+n+1);
printf("Case #%d: %.6lf\n",tt,solve(1,n));
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
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:
result:
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
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 ...