QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#100937#6355. 5SolitaryDream#WA 3ms9072kbC++202.4kb2023-04-28 18:43:072023-04-28 18:43:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-28 18:43:10]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9072kb
  • [2023-04-28 18:43:07]
  • 提交

answer

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

using pii=pair<int,int>;

const int N=2e5+1e3+7;

vector<pii>f[N];

int n,S,c[N];

void trans(int v,int w)
{
    
    // int v=1<<j,w=(i-1)*(1<<j);
    for(int t=S-w;t>=0;t--)    
    {
        int p=t,q=t+w;
        for(auto [l,r]:f[p])
            f[q].push_back({l+v,r+v});
        sort(f[q].begin(),f[q].end());
        vector<pii>nfq;
        int a=-1,b=-1;
        for(auto [l,r]:f[q])
        {
            if(a==-1)
                a=l,b=r;
            else
            {
                if(b<l-1)
                    nfq.push_back({a,b}),a=l,b=r;
                else
                    b=r;
            }
        }
        if(a!=-1)
            nfq.push_back({a,b});
        f[q]=nfq;
    }
}

map<int,vector<pii> >g;

void rtrans(int v,int w)
{
    map<int,vector<pii> >ng=g;
    for(auto [t,fg]:g)
    {
        int p=t,q=t+w;
        for(auto [l,r]:g[p])
            ng[q].push_back({l+v,r+v});
        sort(ng[q].begin(),ng[q].end());
        vector<pii>nfq;
        int a=-1,b=-1;
        for(auto [l,r]:ng[q])
        {
            if(a==-1)
                a=l,b=r;
            else
            {
                if(b<l-1)
                    nfq.push_back({a,b}),a=l,b=r;
                else
                    b=r;
            }
        }
        if(a!=-1)
            nfq.push_back({a,b});
        ng[q]=nfq;
    }
    g=ng;
}

int main()
{
    scanf("%d%d",&n,&S);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        c[x]++;
    }
    f[0].push_back({0,c[1]});
    for(int i=2;i<=S;i++)
    {
        if(!c[i])
            continue;
        int x=c[i];
        for(int j=0;(1<<j)<=x;j++)
        {
            int v=1<<j,w=(i-1)*(1<<j);
            trans(v,w);
            x-=(1<<j);
        }
        if(x)
        {
            int v=x,w=(i-1)*x;
            trans(v,w);
        }
    }
    for(int i=0;i<=S;i++)
        if(f[i].size())
            g[i]=f[i];
    if(c[0])
    {
        int x=c[0];
        for(int j=0;(1<<j)<=x;j++)
        {
            int v=1<<j,w=-(1<<j);
            rtrans(v,w);
            x-=(1<<j);
        }
        if(x)
        {
            int v=x,w=-x;
            rtrans(v,w);
        }
    }
    long long ans=0;
    for(auto [w,i]:g)
        for(auto [x,y]:i)
            ans+=y-x+1;
    printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8264kb

input:

7 9
0 0 0 1 1 2 5

output:

42

result:

ok 1 number(s): "42"

Test #2:

score: 0
Accepted
time: 0ms
memory: 8748kb

input:

10 33
9 9 8 1 1 1 1 1 1 1

output:

48

result:

ok 1 number(s): "48"

Test #3:

score: 0
Accepted
time: 3ms
memory: 9072kb

input:

10 14
2 4 4 1 0 1 0 1 0 1

output:

81

result:

ok 1 number(s): "81"

Test #4:

score: 0
Accepted
time: 0ms
memory: 8272kb

input:

10 14
3 5 3 0 1 0 1 0 1 0

output:

87

result:

ok 1 number(s): "87"

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 8312kb

input:

40 50
1 1 1 1 3 3 0 3 1 1 0 0 2 1 0 0 1 0 0 2 7 1 2 1 3 0 2 2 3 1 1 0 0 2 0 1 1 0 1 1

output:

1064

result:

wrong answer 1st numbers differ - expected: '1067', found: '1064'