This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=505, kx=250005;
int n, a[nx], sm;
bitset<kx> dp[nx];
vector<int> res;
bool valid(int x)
{
for (int i=1; i<=n; i++) if (((sm-a[i]+x)%2)||(!dp[i][(sm-a[i]+x)/2])) return 0;
return 1;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i], sm+=a[i];
for (int i=0; i<=n; i++) dp[i][0]=1;
for (int i=1; i<=n; i++) dp[0]=dp[0]|(dp[0]<<a[i]);
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) if (j!=i) dp[i]=dp[i]|(dp[i]<<a[j]);
if ((sm%2)||!dp[0][sm/2]) return cout<<0, 0;
for (int i=1; i<kx; i++) if (valid(i)) res.push_back(i);
cout<<res.size()<<'\n';
for (auto x:res) cout<<x<<' ';
}
/*
4
1 3 1 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |