#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 500+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int a[N];
bitset<500*250> b1 , b2 , b3;
void solve() {
int n;
cin >> n;
int sum = 0;
int cnt[2];
cnt[0]=cnt[1]=0;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
sum += a[i];
cnt[a[i]%2] = 1;
}
if(sum%2 || cnt[0]==cnt[1]) {
cout << 0;
return;
}
for(int i = 0; i <= n; i ++) {
b3.reset();
for(int j = 1; j <= n; j ++) {
if(i == j) continue;
if(i == 0) {
b2 |= (b2 << a[j]);
b2[a[j]] = 1;
}
else {
b3 |= (b3 << a[j]);
b3[a[j]] = 1;
}
}
if(i) b3 <<= a[i]/2;
if(i == 1) b1 = b3;
if(i > 1) b1 &= b3;
}
if(!b2[sum/2]) {
cout << 0;
return;
}
cout << b2.count() << '\n';
for(int i = 0; i < b2.size(); i ++) {
if(b2[i]) {
cout << i*2-sum << ' ';
}
}
}
/*
1 2 1 2 2
*/
main() {
ios;
int tt = 1;
//cin >> tt;
while(tt --) {
solve();
}
return 0;
}
Compilation message
bootfall.cpp: In function 'void solve()':
bootfall.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < b2.size(); i ++) {
| ~~^~~~~~~~~~~
bootfall.cpp: At global scope:
bootfall.cpp:67:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main() {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |