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;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 555;
ll sum = 0;
ll dp[maxn*maxn];
void add(ll x) {
for (int i=sum; i>=0; i--) {
dp[i+x] += dp[i];
}
sum += x;
}
void sub(ll x) {
for (int i=0; i<=sum; i++) {
dp[i+x] -= dp[i];
}
sum -= x;
}
bool fail[maxn*maxn];
int n;
ll a[maxn];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
dp[0]=1;
cin>>n;
for (int i=0; i<n; i++) {
cin>>a[i];
add(a[i]);
}
if (sum%2) out(0);
if (dp[sum/2]==0) out(0);
for (int i=0; i<n; i++) {
sub(a[i]);
for (int x=1; x<=500*500; x++) {
if ((sum+x)%2==1) {
fail[x]=true;
}
if ((sum+x)%2==0 && dp[(sum+x)/2]==0) {
fail[x]=true;
}
}
add(a[i]);
}
vector<int> ans;
for (int i=1; i<=500*500; i++) {
if (!fail[i]) ans.push_back(i);
}
cout<<ans.size()<<"\n";
for (int x: ans) cout<<x<<" ";
cout<<endl;
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... |