Submission #1284384

#TimeUsernameProblemLanguageResultExecution timeMemory
1284384I_FloPPed21Bootfall (IZhO17_bootfall)C++20
65 / 100
1052 ms2048 KiB
#include <bits/stdc++.h>
using namespace std;
int n;
long long cnt[500*500+1];
int main()
{
    cin>>n;
    long long suma=0;
    vector<int>v(n+1,0);
    for(int i=1; i<=n; i++)
    {
        cin>>v[i];
        suma+=v[i];
    }
    vector<int>ans;
    for(int i=1; i<=n+1; i++)
    {
        bitset<500*500+1>dp;
        dp[0]=1;
        long long suma2=0;
        for(int j=1; j<=n; j++)
        {

            if(i!=j)
            {
                suma2+=v[j];
                dp|=(dp<<v[j]);
            }
        }

        if(i==n+1)
        {
            if(!dp[suma2/2])
            {
                cout<<0<<'\n';
                return 0;
            }
            break;
        }
        for(int j=0; j<=suma; j++)
        {
            if(dp[j])
            {
                //cout<<j<<" "<<dp[j]<<" "<<i<<" "<<suma2<<'\n';
                long long other=suma2-j;
                if(other-j>0)
                {
                    cnt[other-j]++;
                    if(cnt[other-j]==n)
                        ans.push_back(other-j);
                }
            }
        }
    }
    sort(ans.begin(),ans.end());
    if(ans.empty())
        cout<<0;
    else
    {
        cout<<ans.size()<<'\n';
        for(auto u:ans)
            cout<<u<<" ";
    }
    return 0;
}
#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...