QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649974#6436. Paimon Polygonwangyue2017WA 0ms10432kbC++143.3kb2024-10-18 12:02:472024-10-18 12:02:48

Judging History

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

  • [2024-10-18 12:02:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10432kb
  • [2024-10-18 12:02:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define D long double 
#define int long long
#define P pair<int,int>
#define x first
#define y second  
int cross(P a,P b){
    return a.x*b.y-a.y*b.x;
}
P operator-(P a,P b){
    return {a.x-b.x,a.y-b.y};
}
D dist(P a){
    return sqrt(a.x*a.x+a.y*a.y);
}


const int N =1.1e6;
P a[N];
int sk[N],used[N];
int n;
D mx=0;
#define in(x) scanf("%lld",&x)

int hull(){
    int top=0,bas=1;
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i){
        if(used[i])continue;
        while(top>bas&&cross(a[i]-a[sk[top-1]],a[sk[top]]-a[sk[top-1]])>=0)top--;
        sk[++top]=i;
    }
    bas=top;
    for(int i=n-1;i;--i){
        if(used[i])continue;
        while(top>bas&&cross(a[i]-a[sk[top-1]],a[sk[top]]-a[sk[top-1]])>=0)top--;
        sk[++top]=i;
    }
    return top-1;
}
void cover(){
    int t=hull();
    D ans=0;
    sk[t+1]=sk[1];
    for(int i=1;i<=t;++i){
        used[sk[i]]=1;
        ans+=dist(a[sk[i]]-a[sk[i+1]]);
    }
    bool flag=1;
    for(int i=1;i<=n;++i){
        if(a[i]==(P){0,0}){
            if(used[i]==0)
                flag=0;   
            else used[i]=0;
        }
    }
    int tt=hull();
    if(t+tt!=n+1){
        flag=0;
    }
    if(tt<=2)flag=0;
    sk[tt+1]=sk[1];
    for(int i=1;i<=tt;++i){
        ans+=dist(a[sk[i]]-a[sk[i+1]]);
    }
    if(flag)mx=ans;
}
struct dot
{
    int x,y;
    D ang;
}b[N];
bool comp(dot a,dot b){
    return a.ang<b.ang;
}
int L=1,R=0,c1,c2,n1,n2;
void rot(){
    sort(b+1,b+1+n,comp);
    D sm=0;
    for(int i=1;i<=n;++i)a[i]={b[i].x,b[i].y};
    for(int i=n+1;i<=2*n;++i)a[i]=a[i-n];
    for(int i=1;i<n;++i)
    if(cross(a[i+1],a[i])==0&&b[i+1].ang-b[i].ang<1e-9)return;
    for(int i=1;i<=n;++i)sm+=dist(a[i+1]-a[i]);
    
    L=1,R=1,c1=0,c2=0;
    while(b[R+1].ang<=0)R++;
    
    for(int i=1;i<=R;++i){
        if(i+2<=R)if(cross(a[i+2]-a[i],a[i+1]-a[i])>=0)c1++;
    }
    for(int i=R+1;i<=L+n-1;++i){
        if(i+2<=L+n-1)if(cross(a[i+2]-a[i],a[i+1]-a[i])>=0)c2++;
    }
    L=0;
    n1=R+1;n2=n-n1;
    while(L<=n){
        L++;
        n1--;n2++;
        if(n1>=2)if(cross(a[L+1]-a[L-1],a[L]-a[L-1])>=0)c1--;
        if(n2>=3)
        if(cross(a[L-1]-a[L-3+n],a[L-2+n]-a[L-1+n])>=0)c2++;
        if(c1==0&&c2==0&&n1>=2&&n2>=2&&cross(a[R+1],a[L-1+n])>0){
            mx=max(mx,sm-dist(a[L]-a[L-1+n])-dist(a[R]-a[R+1])+dist(a[L])+dist(a[L-1+n])+dist(a[R])+dist(a[R+1]));
        }
        while(cross(a[L],a[R+1])>0||R<L){
            R++;
            n1++;n2--;
            if(n1>=3)if(cross(a[R]-a[R-2],a[R-1]-a[R-2])>=0)c1++;
            if(n2>=2)if(cross(a[R+2]-a[R],a[R+1]-a[R])>=0)c2--;
            if(c1==0&&c2==0&&n1>=2&&n2>=2&&cross(a[R+1],a[L-1+n])>0){
                mx=max(mx,sm-dist(a[L]-a[L-1+n])-dist(a[R]-a[R+1])+dist(a[L])+dist(a[L-1+n])+dist(a[R])+dist(a[R+1]));
            }
        }
    }
}
signed main(){
    int t;
    cin>>t;
    while(t--){
        mx=0;
        in(n);
        for(int i=1;i<=n;++i)in(a[i].x),in(a[i].y);
        for(int i=1;i<=n;++i)b[i].x=a[i].x,b[i].y=a[i].y,b[i].ang=atan2(b[i].y,b[i].x);
        for(int i=1;i<=n+1;++i)used[i]=0;
        a[++n]={0,0};
        cover();
        n--;
        rot();
        printf("%.10Lf\n",mx);
    }    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10432kb

input:

3
4
0 3
3 0
2 3
3 2
5
4 0
5 -5
-4 -2
1 -2
-5 -2
4
0 1
1 0
0 2
1 1

output:

0.0000000000
36.6326947621
0.0000000000

result:

wrong answer 1st numbers differ - expected: '17.2111026', found: '0.0000000', error = '1.0000000'