QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#391413#8005. Crossing the Border2745518585WA 2658ms70676kbC++202.8kb2024-04-16 16:14:552024-04-16 16:14:57

Judging History

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

  • [2024-04-16 16:14:57]
  • 评测
  • 测评结果:WA
  • 用时:2658ms
  • 内存:70676kb
  • [2024-04-16 16:14:55]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=11;
const ll P=998244353;
int n,m,q,b1[1<<N],b2[1<<N];
ll a1[1<<N],a2[1<<N];
vector<int> d1[1<<N],d2[1<<N];
struct pr
{
    int a,b;
}p[N<<1];
struct str
{
    ll s,w;
    str() {}
    str(ll s,ll w):s(s),w(w) {}
    friend str min(const str &a,const str &b)
    {
        if(a.s!=b.s) return a.s<b.s?a:b;
        else return str(a.s,(a.w+b.w)%P);
    }
    friend str operator+(const str &a,ll b)
    {
        return str(a.s+b,a.w);
    }
}f[1<<N][1<<N];
bool cmp(pr a,pr b)
{
    return a.b>b.b;
}
int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d",&p[i].a,&p[i].b);
    }
    sort(p+1,p+n+1,cmp);
    m=n/2;
    n-=m;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=(1<<n)-1;++j)
        {
            if(j&(1<<(i-1))) a1[j]+=p[i].a,b1[j]=max(b1[j],p[i].b);
        }
    }
    for(int i=1;i<=m;++i)
    {
        for(int j=0;j<=(1<<m)-1;++j)
        {
            if(j&(1<<(i-1))) a2[j]+=p[n+i].a,b2[j]=max(b2[j],p[n+i].b);
        }
    }
    for(int i=0;i<=(1<<n)-1;++i)
    {
        d1[i].push_back(i&-i);
        for(int j=(i^(i&-i));j;j=(j-1)&(i^(i&-i))) d1[i].push_back(j|(i&-i));
        sort(d1[i].begin(),d1[i].end(),[&](int x,int y){return a1[x]<a1[y];});
    }
    for(int i=0;i<=(1<<m)-1;++i)
    {
        d2[i].push_back(0);
        for(int j=((1<<m)-1)^i;j;j=(j-1)&(((1<<m)-1)^i)) d2[i].push_back(j);
        sort(d2[i].begin(),d2[i].end(),[&](int x,int y){return a2[x]>a2[y];});
    }
    for(int i=0;i<=(1<<n)-1;++i)
    {
        for(int j=0;j<=(1<<m)-1;++j) f[i][j]=str(1e18,0);
    }
    f[0][0]=str(0,1);
    for(int i=0;i<=(1<<m)-1;++i)
    {
        for(int j=i;j;j=(j-1)&i)
        {
            if(a2[j]<=q) f[0][i]=min(f[0][i],f[0][i^j]+b2[j]);
        }
    }
    for(int i=1;i<=(1<<n)-1;++i)
    {
        for(int j=0;j<=(1<<m)-1;++j)
        {
            auto x=d2[j].begin();
            while(x!=d2[j].end()&&a1[i&-i]+a2[*x]>q) ++x;
            str w=str(1e18,0);
            for(auto k:d1[i])
            {
                while(x!=d2[j].end()&&a1[k]+a2[*x]>q)
                {
                    f[i][j^(*x)]=min(f[i][j^(*x)],w);
                    ++x;
                }
                w=min(w,f[i^k][j]+b1[k]);
            }
            while(x!=d2[j].end())
            {
                f[i][j^(*x)]=min(f[i][j^(*x)],w);
                ++x;
            }
        }
    }
    // for(int i=0;i<=(1<<n)-1;++i)
    // {
    //     for(int j=0;j<=(1<<m)-1;++j)
    //     {
    //         printf("%d %d %lld\n",i,j,f[i][j]);
    //     }
    // }
    printf("%lld %lld\n",f[(1<<n)-1][(1<<m)-1].s,(f[(1<<n)-1][(1<<m)-1].w%P+P)%P);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5856kb

input:

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

output:

9 4

result:

ok 2 number(s): "9 4"

Test #2:

score: 0
Accepted
time: 72ms
memory: 20636kb

input:

18 10000000
956231 904623
1692946 1796774
1081323 1170319
3218792 2542661
3183376 3037270
1869132 1442561
35436 35018
1564635 1939950
1847344 2006043
755870 899310
1671882 2057413
1369264 1338951
3132483 3504034
2056224 1825640
1840949 1562071
1514040 1405352
2300821 2421801
2466540 3004920

output:

9391997 70

result:

ok 2 number(s): "9391997 70"

Test #3:

score: 0
Accepted
time: 422ms
memory: 38452kb

input:

20 10000000
1289384 1416015
1692778 1966748
1747794 1708650
2885387 2925290
2516650 2410838
2202363 2092667
368691 407497
1897764 1902790
180541 224758
1089173 1075924
2005212 1743637
702568 566295
465783 369143
2722863 2902398
174068 150211
513930 519657
1634023 1313239
1133070 1040937
961394 11066...

output:

6331196 89

result:

ok 2 number(s): "6331196 89"

Test #4:

score: 0
Accepted
time: 1165ms
memory: 69316kb

input:

21 10000000
1432782 1230128
1693282 1456826
605524 521515
2742745 3427204
2231114 2129928
2345527 2397808
511783 521160
2041234 2313965
2323807 2603481
1232121 1410811
719508 850004
416942 495559
2180169 2579591
1580089 1786914
2317568 2292171
1514260 1143717
1348703 1495001
562052 525544
2818854 23...

output:

9336572 5

result:

ok 2 number(s): "9336572 5"

Test #5:

score: 0
Accepted
time: 2658ms
memory: 70588kb

input:

22 10000000
1562592 1176882
1693226 1513484
2293770 2757728
2612851 3010518
1971354 2392268
2475363 2035487
641627 684375
2171036 2181775
1544541 1633457
1361981 1060447
2277948 2792254
157192 141039
1011327 1139897
541119 577682
1538276 1451191
2423314 2061841
1088919 1154927
42526 43789
1779858 16...

output:

8019829 516

result:

ok 2 number(s): "8019829 516"

Test #6:

score: -100
Wrong Answer
time: 1987ms
memory: 70676kb

input:

22 50000000
9900000 50000000
9800000 50000000
9700000 50000000
9600000 50000000
9500000 50000000
9400000 50000000
9300000 50000000
9200000 50000000
9100000 50000000
9190000 50000000
9180000 50000000
9170000 50000000
9160000 50000000
9150000 50000000
9140000 50000000
9130000 50000000
9120000 50000000...

output:

250000000 513037463

result:

wrong answer 2nd numbers differ - expected: '659827482', found: '513037463'