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>
#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] , u[N];
bitset<500*250> b1 , 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 ++) {
if(u[a[i]]) continue;
u[a[i]] = 1;
b3.reset();
for(int j = 1; j <= n; j ++) {
if(i == j) continue;
b3 |= (b3 << a[j]);
b3[a[j]] = 1;
}
if(i == 0 && !b3[sum/2]) {
cout << 0;
return;
}
if(i) b3 <<= a[i]/2;
if(i == 1) b1 = b3;
if(i > 1) b1 &= b3;
}
vector<int> ans;
int sta = 0;
if(cnt[1]) sta = 1;
for(int i = sta; i <= sum; i += 2) {
int cur = (sum+i)/2;
if(b1[cur]) ans.push_back(i);
}
sort(all(ans));
cout << ans.size() << '\n';
for(auto to: ans) {
cout << to << ' ';
}
}
/*
1 2 1 2 2
*/
main() {
ios;
int tt = 1;
//cin >> tt;
while(tt --) {
solve();
}
return 0;
}
Compilation message (stderr)
bootfall.cpp:69:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
69 | main() {
| ^
# | 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... |