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>
using namespace std;
typedef long long ll;
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
const int N = 1e5 + 5, M = 1e6 + 5, mod = 1e9 + 7;
int n, s, a[505], dp[25005];
bitset <25005> on;
void add(int x){
fa(i,s,x) {
dp[i] += dp[i-x];
dp[i] %= mod;
}
}
void res(int x){
f(i,x,s+1){
dp[i] = (dp[i] - dp[i-x] + mod) % mod;
}
}
int main(){
cin >> n;
f(i,1,n+1) {
cin >> a[i];
s += a[i];
}
dp[0] = 1;
f(i,1,n+1){
add(a[i]);
}
if(s&1 or dp[s/2] == 0){
cout << "0\n";
return 0;
}
f(i,1,s+1) on[i] = 1;
f(i,1,n+1){
res(a[i]);
int x = s - a[i];
f(j,1,s+1){
if(x%2 != j%2 or dp[(x+j)/2] == 0) on[j] = 0;
}
add(a[i]);
}
cout << on.count() << "\n";
f(i,1,s+1) if(on[i]) cout << i << " ";
cout << "\n";
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... |