QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#536606 | #5809. Min Perimeter | zhicheng | 5 | 125ms | 4188kb | C++14 | 1.3kb | 2024-08-29 14:56:33 | 2024-08-29 14:56:33 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
namespace IO{
inline char gc(){
static const int Rlen=1<<18|1;static char buf[Rlen],*p1,*p2;
return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>T get_integer(){
char c;bool f=false;while(!isdigit(c=gc()))f=c=='-';T x=c^48;
while(isdigit(c=gc()))x=((x+(x<<2))<<1)+(c^48);return f?-x:x;
}
inline int gi(){return get_integer<int>();}
}
using namespace std;
using namespace IO;
const int N=1000010;
int n;
struct s{
int x,y;
bool operator<(s b){
return x<b.x;
}
bool operator==(s b){
return x==b.x&&y==b.y;
}
}p[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 dis(int i,int j){
return dist(p[i],p[j]);
}
void solve(){
double ans=1e18,sum;
sort(p+1,p+n+1);
for(int i=1;i<=n;i++){
for(int j=i+2;j<=min(n,i+500);j++){
if(dis(i,j)>=ans/2){
continue;
}
if(p[j].x-p[i].x>=ans/2){
break;
}
sum=1e18;
for(int k=i+1;k<=j-1;k++){
sum=min(sum,dis(i,k)+dis(k,j));
}
ans=min(ans,sum+dis(i,j));
}
}
printf("%.6lf\n",ans);
}
int main(){
int t=gi();
for(int tt=1;tt<=t;tt++){
n=gi();
for(int i=1;i<=n;i++){
p[i].x=gi();
p[i].y=gi();
}
printf("Case #%d: ",tt);
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 125ms
memory: 4188kb
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.893012 Case #2: 1042.844835 Case #3: 1711142102.791327 Case #4: 90912.296374 Case #5: 3.414214 Case #6: 26.153830 Case #7: 1701.012681 Case #8: 2865438.191994 Case #9: 2020088.337226 Case #10: 1792106.037292 Case #11: 2019352.542910 Case #12: 2530195.728018 Case #13: 930517.779631 Case #...
result:
ok correct! (15 test cases)
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 ...