제출 #724698

#제출 시각아이디문제언어결과실행 시간메모리
724698DenkataBootfall (IZhO17_bootfall)C++14
100 / 100
45 ms2016 KiB
#include<bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 503;
bitset <250006> ans;
bitset <250006> tek;
bitset <250006> newtek;
int i,j,p,q,n,m,k,sum;
int a[maxn];
void rek(int l,int r,bitset <250006> tek)
{

    if(l>r)return ;
    if(l==r)
    {
        ///managed to compute the knapsack in tek without this one
        tek=(tek<<a[l]);
        ans&=tek;
        return ;
    }

    int mid = (l+r)/2;
    ///l mid; mid+1 r
    newtek = tek;
    for(i=r;i>=mid+1;i--)
        newtek|=(newtek<<(2*a[i]));
    rek(l,mid,newtek);
    newtek = tek;
    for(i=l;i<=mid;i++)
        newtek|=(newtek<<(2*a[i]));
    rek(mid+1,r,newtek);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%2!=0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(i=2;i<=n;i++)
    {
        if(a[i]%2!=a[i-1]%2)
        {
            cout<<0<<endl;
            return 0;
        }
    }
    newtek[0]=1;
    for(i=1;i<=n;i++)
        newtek|=(newtek<<(a[i]));
    if(!newtek[sum/2])
    {
        cout<<0<<endl;
        return 0;
    }
    ans.set();
    tek.set(0);
    tek[0]=1;
    rek(1,n,tek);
    int br = 0;
    for(i=1;i<sum;i++)
        if(ans[i])br++;
    cout<<br<<endl;
    for(i=sum-1;i>1;i--)
    {
        if(ans[i])
            cout<<sum-i<<" ";
    }
    return 0;
}
/**
4
1 3 1 5

4
200 200 200 200
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...