#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;
const long long MAXN=505;
long long a[MAXN];
bool isNotAns[501*501];
vector<long long> NotPossSums(long long arr[], long long n);
int main()
{
long long n, sum=0;
cin>>n;
for (long long i=0; i<n; i++)
{
cin>>a[i];
sum+=a[i];
}
vector<long long> temp=NotPossSums(a, n);
auto it=lower_bound(temp.begin(), temp.end(), sum/2);
if (sum%2 || (it!=temp.end() && *it==sum/2)) {
cout<<"0\n";
return 0;
}
for (long long j=0; j<n; j++)
{
swap(a[j], a[n-1]);
vector<long long> temp=NotPossSums(a, n-1);
swap(a[j], a[n-1]);
for (long long x=1; x<=sum; x++)
if ((sum-a[j]+x)%2 || (sum-a[j]+x)/2-x<0)
isNotAns[x]=true;
for (long long i=0; i<temp.size(); i++)
{
long long cur=temp[i];
if (sum-a[j]-2*cur>0) isNotAns[sum-a[j]-2*cur]=true;
}
}
vector<long long> ans;
for (long long x=1; x<=sum; x++)
if (!isNotAns[x])
ans.push_back(x);
cout<<ans.size()<<'\n';
for (long long i=0; i<ans.size(); i++)
cout<<ans[i]<<' ';
cout<<'\n';
char I;
cin >> I;
return 0;
}
bool dp[MAXN][1000000];
vector<long long> NotPossSums(long long arr[], long long n)
{
long long sum=0;
for (long long i=0; i<n; i++)
sum+=arr[i];
memset(dp, 0, sizeof(dp));
for (long long i=0; i<=n; i++)
dp[i][0]=true;
for (long long i=1; i<=n; i++)
{
dp[i][arr[i-1]]=true;
for (long long j=1; j<=sum; j++)
{
if (dp[i-1][j]==true)
{
dp[i][j]=true;
dp[i][j+arr[i-1]]=true;
}
}
}
vector<long long> res;
for (long long j=0; j<=sum; j++)
if (!dp[n][j])
res.push_back(j);
return res;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:38:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long long i=0; i<temp.size(); i++)
~^~~~~~~~~~~~
bootfall.cpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (long long i=0; i<ans.size(); i++)
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
175 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |