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 <bitset>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
if(n % 2 != 0){
cout << 0;
return 0;
}
vector<int> a(n);
for(int i = 0; i < n; i ++) cin >> a[i];
int k = a[0] & -a[0], s = 0;
for(int i = 0; i < n; i ++){
if((a[i] & -a[i]) != k){
cout << 0;
return 0;
}
a[i] /= k;
s += a[i];
}
vector<bitset<500>> dp(s+1);
vector<bool> can(s+1);
can[0] = true;
int s1 = 0;
for(int i = 0; i < n; i ++){
s1 += a[i];
for(int j = s1; j >= a[i]; j --){
if(can[j - a[i]]){
if(!can[j]){
dp[j] = dp[j-a[i]];
dp[j].set(i, 1);
}
else dp[j] = dp[j] & dp[j-a[i]];
can[j] = true;
}
}
}
if(!can[s/2]){
cout << 0;
return 0;
}
vector<int> res;
for(int x = 1; x <= s; x += 2){
bool f = true;
for(int i = 0; i < n; i ++)
if(!can[(s + x - a[i]) / 2] || dp[(s + x - a[i]) / 2][i]){
f = false;
break;
}
if(f)
res.push_back(x);
}
cout << res.size() << '\n';
for(int x:res) cout << x * k << ' ';
return 0;
}
# | 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... |