QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390958#8005. Crossing the BordermarherWA 0ms8052kbC++142.6kb2024-04-16 09:47:072024-04-16 09:47:07

Judging History

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

  • [2024-04-16 09:47:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8052kb
  • [2024-04-16 09:47:07]
  • 提交

answer

#pragma GCC optimize("Ofast","inline")
#include<bits/stdc++.h>
#define lb(x) (x&(-x))
using namespace std;
const int N=(1<<22),M=22,mod=998244353;

int md(int x)
{
    return x>=mod?x-mod:x;
}

struct node
{
    int w,s;

    friend node operator+(node a,node b)
    {
        if(a.w==b.w)return (node){a.w,md(a.s+b.s)};
        return a.w<b.w?a:b;
    }
    
    friend node operator*(node a,node b)
    {
        return (node){a.w+b.w,(int)(1ll*a.s*b.s%mod)};
    }
}f[N],g[N];

struct poi
{
    int c,w;

    friend bool operator<(poi a,poi b)
    {
        return a.c<b.c;
    }
}a[M];

int n,m,sum[N],w,mx[N],mb[N],A[N],top;
vector<int>B[1<<11];

int cmp1(int a,int b)
{
    return sum[a]>sum[b];
}

int cmp2(int a,int b)
{
    return sum[a]<sum[b];
}

void solve(int m,int d)
{
    for(int i=1;i<(1<<m);i++)
    {
        int t=i<<d;
        if(sum[t]<=w)
        {
            f[t]=(node){mx[t],1};
            continue;
        }
        f[t].w=2e9;
        int p=t^lb(t);
        for(int s=p;s;s=(s-1)&p)f[t]=f[t]+(f[s]*f[t^s]);
    }
}

int main()
{
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    cin>>n>>w;m=n/2;
    for(int i=0;i<n;i++)cin>>a[i].w>>a[i].c;
    sort(a,a+n);
    for(int i=0;i<n;i++)sum[1<<i]=a[i].w,mx[1<<i]=a[i].c,mb[1<<i]=(1<<i);
    for(int i=1;i<(1<<n);i++)if(lb(i)^i)sum[i]=sum[i^lb(i)]+sum[lb(i)],mx[i]=max(mx[i^lb(i)],mx[lb(i)]),mb[i]=mb[i-1];
    for(int i=0;i<(1<<n-m);i++)
    {
        for(int s=(i^mb[i]);s;s=(s-1)&(i^mb[i]))if(sum[i^(s<<m)]<=w)B[i].push_back(s<<m);
        B[i].push_back(0);sort(B[i].begin(),B[i].end(),cmp2);
    }
    f[0]=(node){0,1};solve(m,0);solve(n-m,m);
    for(int i=1;i<(1<<m);i++)
    {
        top=0;
        for(int s=(i&(i-1));s;s=((s-1)&i))A[top++]=s;A[top++]=0;
        sort(A,A+top,cmp1);
        for(int s=0;s<(1<<n-m);s++)
        {
            node now;now.w=2e9;
            for(int j=0;j<top;j++)g[(s<<m)|A[j]]=now=now+f[(s<<m)|A[j]];
        }
        for(int s=1;s<(1<<n-m);s++)
        {
            int pos=0,t=(s<<m)|i,rw=mx[s<<m];f[t].w=2e9;
            if(sum[t]<=w)
            {
                f[t]=(node){mx[t],1};
                continue;
            }
            for(auto x:B[s])
            {
                if(sum[(s<<m)^x]<=w)f[t]=f[t]+(f[i|x]*(node){rw,1});
                while(pos<top&&sum[i|(s<<m)]-sum[A[pos]]-sum[x]<=w)pos++;
                if(pos)f[t]=f[t]+(g[A[pos-1]|x]*(node){rw,1});
            }
        }
    }
    cout<<f[(1<<n)-1].w<<' '<<f[(1<<n)-1].s<<'\n';
    cerr<<1.0*clock()/CLOCKS_PER_SEC;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
3 5
1 4
2 3
2 2
2 1

output:

9 3

result:

wrong answer 2nd numbers differ - expected: '4', found: '3'