#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i <= (int)b; i++)
#define FORD(i, a, b) for(int i = a; i >= (int)b; i--)
#define pb push_back
#define fi first
#define se second
#define ALL(A) A.begin(), A.end()
#define BIT(mask,i) ((mask>>(i))&1)
#define ll long long
using namespace std;
template <class A, class B> bool maximize(A &a, const B b) {if(a<b){a = b;return 1;} return 0;}
template <class A, class B> bool minimize(A &a, const B b) {if(a>b){a = b;return 1;} return 0;}
const int maxn = 3e5 + 5;
int n;
int a[505];
void init() {
cin >> n;
FOR(i, 1, n) cin >> a[i];
}
namespace sub1 {
bitset <300 * 300 + 5> dp;
bool check (int val) {
a[n + 1] = val;
FOR(i, 1, n) {
int sum = 0;
FOR(j, 1, n + 1) if (i != j) sum+= a[j];
if (sum & 1) return 0;
dp.reset();
dp[0] = 1;
FOR(j, 1, n + 1) if (i != j) dp |= dp << a[j];
if (dp[sum / 2] == 0) return false;
}
return true;
}
void solve() {
int sum = 0;
FOR(i, 1, n) sum+= a[i];
if (sum & 1) return void(cout << 0);
dp[0] = 1;
FOR(i, 1, n) dp |= dp << a[i];
if (dp[sum / 2] == 0) return void(cout << 0);
vector <int> ans;
FOR(i, 0, sum) if (check(i)) ans.push_back(i);
cout << (int)ans.size() << '\n';
for (int &val : ans) cout << val << ' ';
}
}
void process() {
return sub1::solve();
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define ko "kieuoanh"
if (fopen(ko".inp", "r")) {
freopen(ko".inp", "r", stdin);
freopen(ko".out", "w", stdout);
}
init();
process();
return 0;
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(ko".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen(ko".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |