#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 fi first
#define se second
#define pb push_back
#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 = 505;
int n;
int a[maxn];
void init()
{
cin >> n;
FOR(i, 1, n) cin >> a[i];
}
//bitset <500 * 500> dp;
bool dp[25005];
bool check(int val)
{
a[n + 1] = val;
FOR(i, 1, n + 1)
{
vector <int> rem;
int sum = 0;
FOR(j, 1, n + 1) if(i != j) sum+= a[j], rem.push_back(a[j]);
if(sum & 1) return 0;
FOR(j, 0, sum / 2) dp[j] = 0;
dp[0] = 1;
for(int val : rem)
{
FORD(j, sum / 2, val)
{
dp[j]|= dp[j - val];
}
}
if(dp[sum / 2] == 0) return 0;
}
return 1;
}
void process()
{
vector <int> res;
sort(a + 1, a + 1 + n);
int sum = 0;
FOR(i, 1, n) sum+= a[i];
FOR(i, 1, sum) if(check(i)) res.push_back(i);
cout << res.size() << '\n';
for(int &val : res) cout << val << ' ';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#define Hori "kieuoanh"
if(fopen(Hori".inp", "r"))
{
freopen(Hori".inp", "r", stdin);
freopen(Hori".out", "w", stdout);
}
init();
process();
return 0;
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(Hori".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
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(Hori".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... |