QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196805#6517. Computational Geometryucup-team870RE 0ms0kbC++172.1kb2023-10-01 23:17:502023-10-01 23:17:51

Judging History

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

  • [2023-10-01 23:17:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-01 23:17:50]
  • 提交

answer

//凸包的相邻两段可能共线....
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,l,r) for(int i=l;i>=r;i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
const int N=5e3+5;
struct P{
    int x,y;
}q[N*2];
P operator -(P a,P b){
    return {a.x-b.x,a.y-b.y};
}
bool coline(P a,P b){
    return 1ll*a.x*b.y==1ll*a.y*b.x;
}
ll dis(P a,P b){
    return 1ll*(a.x-b.x)*(a.x-b.x)+1ll*(a.y-b.y)*(a.y-b.y);
}
ll ans[N][N],ma[N*2];
void slv(){
    int n;cin>>n;
    auto cal=[&](int x){return (x%n+n)%n;};
    rep(i,0,n-1){
        cin>>q[i].x>>q[i].y; q[i+n]=q[i];
    }
    rep(i,0,n-1)rep(j,0,n-1)ans[i][j]=0;
    rep(i,0,2*n-1)ma[i]=0;
    per(i,n*2-2,n){
        rep(j,i+1,min(2*n-1,i+n-2))ma[j]=max(ma[j],dis(q[i],q[j]));
    }
    per(i,n-1,0){
        rep(j,i+1,i+n-2)ma[j]=max(ma[j],dis(q[i],q[j]));
        ll val=ma[i+1]; int ok=0;
        rep(j,i+2,i+n-2){
            if(!coline(q[j]-q[j-1],q[j-1]-q[j-2]))ok=1;
            val=max(val,ma[j]); 
            if(ok)ans[i][j%n]+=val;
            else ans[i][j%n]+=6e18;
        }
    }
    reverse(q,q+n); rep(i,0,n-1)q[i+n]=q[i];
    rep(i,0,2*n-1)ma[i]=0;
    per(i,n*2-2,n){
        rep(j,i+1,min(2*n-1,i+n-2))ma[j]=max(ma[j],dis(q[i],q[j]));
    }
    per(i,n-1,0){
        rep(j,i+1,i+n-2)ma[j]=max(ma[j],dis(q[i],q[j]));
        ll val=ma[i+1]; int ok=0;
        rep(j,i+2,i+n-2){
            if(!coline(q[j]-q[j-1],q[j-1]-q[j-2]))ok=1;
            val=max(val,ma[j]); 
            if(ok)ans[cal(n-1-i)][cal(n-1-j)]+=val;
            else ans[cal(n-1-i)][cal(n-1-j)]+=6e18;
        }
    }
    ll res=5e18;
    rep(i,0,n-1){
        // assert(ans[i][i+1]==0);
        rep(j,i+2,n-1){
            assert(ans[i][j]==ans[j][i]);
            if(i==0 && j==n-1)continue;
            res=min(res,ans[i][j]);
        }
    }
    cout<<res<<'\n';
}
int main() {
    IOS
    int T;cin>>T;
    while(T--)slv();
    return 0;
}
/*
2
4
1 0
2 0
1 1
0 0
6
10 4
9 7
5 7
4 5
6 4
9 3

1000000000
*/

詳細信息

Test #1:

score: 0
Runtime Error

input:

2
4
1 0
2 0
1 1
0 0
6
10 4
9 7
5 7
4 5
6 4
9 3

output:


result: