QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639274#9458. TriangulationAfterlifeWA 0ms5676kbC++174.1kb2024-10-13 18:39:232024-10-13 18:39:23

Judging History

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

  • [2024-10-13 18:39:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5676kb
  • [2024-10-13 18:39:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

int T;

const int N=18;

int w[N][N];

struct P {
    int x,y;
    int id;
};

bool operator <(const P &a,const P &b)
{
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}

P operator -(const P &a,const P &b)
{
    return {a.x-b.x,a.y-b.y};
}

int det(const P &a,const P &b)
{
    return a.x*b.y-a.y*b.x;
}

int n;

vector<P> p;

int ok[N][N][N];

vector<P> conv(vector<P> v)
{
    vector<P> c;
    sort(v.begin(),v.end());
    for(auto p:v)
    {
        while(c.size()>1&&det(p-c.back(),p-c.end()[-2])>=0)
            c.pop_back();
        c.push_back(p);
    }
    int m=c.size();
    reverse(v.begin(),v.end());
    for(auto p:v)
    {
        while(c.size()>m&&det(p-c.back(),p-c.end()[-2])>=0)
            c.pop_back();
        c.push_back(p);
    }
    c.pop_back();
    return c;
}

using pii=pair<int,int>;

pii merge(const pii &a,const pii &b)
{
    if(a.first<b.first)
        return a;
    else if(a.first>b.first)
        return b;
    else
        return {a.first,a.second+b.second};
}

pii f[1<<N][N];

int ed,v[1<<N][N];

pii dfs(int S,int l)
{
    if(S==ed)
        return {0,1};
    if(v[S][l])
        return f[S][l];
    v[S][l]=1;
    pii &ret=f[S][l];
    ret.first=1e18;
    vector<int> vs;
    for(int i=0;i<n;i++)
        if(S>>i&1)
            vs.push_back(i);
    int e=0;
    for(int i=1;i+1<n;i++)
    {
        while(e+1<vs.size()&&vs[e+1]<=i)
            e++;
        if(i==l)
            continue;
        if(i<l)
        {
            int T=S|(1<<i)|(1<<l);
            T>>=i+1;
            if(__builtin_ctz(T)!=(l-i-1))
                continue;
        }
        if(S>>i&1)
        {
            int j=vs[e-1],k=vs[e+1];
            if(ok[j][i][k]==-1)
            {
                auto W=dfs(S^(1<<i),i);
                W.first+=w[j][k];
                ret=merge(ret,W);
            }
        }
        else
        {
            int j=vs[e],k=vs[e+1];
            if(ok[j][i][k]==1)
            {
                auto W=dfs(S^(1<<i),i);
                W.first+=w[j][i]+w[i][k];
                ret=merge(ret,W);
            }
        }
    }
    return ret;
}

signed main()
{
    cin>>T;
    while(T--)
    {
        cin>>n;
        p.resize(n);
        int z=0;
        int cs=rand()%1000,sn=rand()%1000;
        for(auto &[x,y,id]:p)
        {
            id=z++;
            cin>>x>>y;
            int u=cs*x-sn*y,v=sn*x+cs*y;
            x=u,y=v;
        }
        sort(p.begin(),p.end());
        vector<int> pos(n);
        for(int i=0;i<n;i++)
            pos[p[i].id]=i;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                cin>>w[pos[i]][pos[j]];
        for(int i=0;i<n;i++)
            p[i].id=i;
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
                for(int k=j+1;k<n;k++)
                {
                    auto z=conv({p[i],p[j],p[k]});
                    ok[i][j][k]=1;
                    for(int l=0;l<n;l++)
                    {
                        auto u=p[l];
                        bool in=1;
                        for(int j=0;j<3;j++)
                            if(det(z[(j+1)%3]-z[j],u-z[j])<=0)
                                in=0;
                        if(in)
                            ok[i][j][k]=0;
                    }
                    if(!ok[i][j][k])
                        continue;
                    if(det(p[i]-p[j],p[k]-p[j])>0)
                        ok[i][j][k]=-1;
                }
        for(int S=0;S<(1<<n);S++)
            for(int i=0;i<n;i++)
                v[S][i]=0;
        auto c=conv(p);
        auto m=max_element(c.begin(),c.end())-c.begin();
        ed=0;
        int st=0;
        for(int i=0;i<=m;i++)
            st|=1<<c[i].id;
        for(int j=m;j<c.size();j++)
            ed|=1<<c[j].id;
        ed|=1<<c[0].id;
        auto ans=dfs(st,0);
        for(int i=0;i+1<=m;i++)
            ans.first+=w[c[i].id][c[i+1].id];
        cout<<ans.first<<" "<<ans.second<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
0 0
1 1
1 0
0 1
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
4
0 0
3 0
1 3
1 1
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

output:

1000000000000000002 0
1000000000000000002 0

result:

wrong answer 1st lines differ - expected: '5 2', found: '1000000000000000002 0'