QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#855254#9728. Catch the Starrotcar07WA 0ms3976kbC++232.2kb2025-01-12 16:42:522025-01-12 16:42:52

Judging History

This is the latest submission verdict.

  • [2025-01-12 16:42:52]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3976kb
  • [2025-01-12 16:42:52]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
namespace geometry{
    constexpr double eps=1e-10;
    using ld=long double;
    using ll=long long;
    using type=int;
    using prt=ll;
    int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
    int sgn(ll a){return a<0?-1:(a>0?1:0);}
    // 2D vector
    struct vec{
        type x,y;
        vec(type _x=0, type _y=0):x(_x),y(_y){}
        vec operator + (const vec& o)const{return vec(x+o.x,y+o.y);}
        vec operator - (const vec& o)const{return vec(x-o.x,y-o.y);}
        vec operator - ()const{return vec(-x,-y);}
        prt operator * (const vec& o)const{return prt(x)*o.x+prt(y)*o.y;}
        prt operator ^ (const vec& o)const{return prt(x)*o.y-prt(y)*o.x;}
        //return norm of the vector.
        prt len()const{return prt(x)*x+prt(y)*y;}
    };
    // return whether AC is in the counterclockwise side of AB (strictly).
    bool chkrt(const vec& A,const vec& B,const vec& C){return sgn((B-A)^(C-A))<0;}
    // return whether AC is in the counterclockwise side of AB (not strictly).
    bool _chkrt(const vec& A,const vec& B,const vec& C){return sgn((B-A)^(C-A))<=0;}
    // return the convex hull of point set P in counter-clockwise order.
    vector<vec> convex_hull(vector<vec>&P){
        sort(P.begin(),P.end(),[&](const auto&x,const auto&y){return x.x==y.x?x.y<y.y:x.x<y.x;});
        vector<vec> st;
        for(const auto&x:P){
            while(st.size()>1&&_chkrt(st.end()[-2],st.back(),x)) st.pop_back();
            st.push_back(x);
        }
        const int siz=st.size();
        for(int i=int(P.size())-2;~i;i--){
            while(st.size()>siz&&_chkrt(st.end()[-2],st.back(),P[i])) st.pop_back();
            st.push_back(P[i]);
        }st.pop_back();
        return st;
    }
    // return the perimeter of the polygon P.
    ld perimeter(const vector<vec>&P){
        ld res=sqrt((P[0]-P.back()).len());
        for(int i=0;i+1<P.size();i++) res+=sqrt((P[i]-P[i+1]).len());
        return res;
    }
}
using namespace geometry;
int main(){
    std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    vector<vec>v(n);
    for(auto&[x,y]:v) cin>>x>>y;
    cout<<fixed<<setprecision(10)<<perimeter(convex_hull(v))<<'\n';
}

詳細信息

Test #1:

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

input:

2
4 -8 8
3 -7 7 -6 8 -7 8
3 -9 -2 -7 3 -9 -1
3 -2 3 0 2 -4 5
3 5 1 5 3 4 2
3 1 -1 2 -2 3 -1
5 -8 8
5 -14 -3 -10 -2 -9 2 -10 4 -12 5
3 -16 0 -15 0 -15 1
3 -15 6 -9 5 -15 7
3 -10 5 -9 5 -10 6
3 -7 3 -3 2 -8 4
3 -6 -1 -6 -2 -5 -1

output:

23.4093998214

result:

wrong answer 1st numbers differ - expected: '9.4047619', found: '23.4093998', error = '1.4891007'