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 maxn = 507;
int D[maxn * maxn], a[maxn];
int main()
{
// freopen("TEST.INP", "r", stdin);
// freopen("TEST.OUT", "w", stdout);
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i], sum += a[i];
D[0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = sum / 2; j >= 0; --j)
D[j + a[i]] += D[j];
if ((sum & 1) || !D[sum / 2]) return cout << 0, 0;
vector <int> cnt(sum + 1);
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= sum; ++j)
D[j + a[i]] -= D[j];
for (int j = 1; j <= sum; ++j)
{
int val = sum - a[i] + j;
cnt[j] += (val / 2 - j >= 0 && 1 - val % 2 && D[val / 2 - j]);
}
for (int j = sum / 2; j >= 0; --j)
D[j + a[i]] += D[j];
}
vector <int> ans;
for (int i = 1; i <= sum; ++i)
if (cnt[i] == n) ans.push_back(i);
cout << (int)ans.size() << '\n';
for (int x: ans) cout << x << ' ';
return 0;
}
# | 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... |