#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops,inline,fast-math")
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
const int MAXN = 270;
const int MAXA = 270;
const int SZ = MAXN * MAXA + 1;
#else
const int MAXN = 20;
const int MAXA = 20;
const int SZ = MAXN * MAXA + 1;
#endif
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto& el : a)
cin >> el;
sort(a.begin(), a.end(), greater<>());
auto adddp = [&](const bitset<SZ>& bs, int a) {
bitset<SZ> res;
res = (bs << a) | (bs >> a);
int curi = bs._Find_first();
while (curi < a) {
res[a - curi] = 1;
curi = bs._Find_next(curi);
}
return res;
};
bitset<SZ> cur;
cur[0] = 1;
for (int i = 0; i < n; ++i)
cur = adddp(cur, a[i]);
if (!cur[0]) {
cout << 0;
return 0;
}
bitset<SZ> ans;
ans.set();
for (int i = 0; i < n; ++i) {
bitset<SZ> bs;
bs[0] = 1;
for (int j = 0; j < n; ++j)
if (i != j)
bs = adddp(bs, a[j]);
ans &= bs;
}
vector<int> vars;
for (int i = 1; i <= MAXN * MAXA; ++i)
if (ans[i])
vars.push_back(i);
cout << vars.size() << '\n';
for (auto el : vars)
cout << el << ' ';
}
# | 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... |