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 <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#define int int64_t
using namespace std;
signed main()
{
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int m = accumulate(v.begin(), v.end(), 0);
vector<int> dp(m + 1);
dp[0] = 1;
for (int i = 0; i < n; i++)
{
for (int j = m; j >= v[i]; j--) dp[j] += dp[j - v[i]];
}
if (m % 2 == 1 || dp[m/2] == 0)
{
cout << "0\n";
return 0;
}
vector<bool> res(m + 1, true);
for (int i = 0; i < n; i++)
{
vector<int> poss(m + 1);
for (int j = 0; j <= m; j++)
{
poss[j] = dp[j] - (j >= v[i] ? poss[j - v[i]] : 0);
}
for (int j = 0; j <= m; j++)
{
if ((m - v[i] + j) & 1) res[j] = false;
else res[j] = res[j] & (poss[(m - v[i] + j) / 2] > 0);
}
}
int r = count(res.begin() + 1, res.end(), true);
cout << r << "\n";
for (int i = 1; i <= m; i++) if (res[i]) cout << i << " ";
cout << "\n";
}
# | 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... |