#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=500+5;
int a[N];
bool dp[N][N];
bool can(int n=500, int sum=0) {
memset(dp,0,N);
dp[0][0]=1;
int nd=sum/2;
if (sum%2==0) {
for (int i = 1; i<=n; i++) {
for (int j = 0; j<=nd; j++) {
if (a[i-1]<=j) dp[i][j]=(dp[i-1][j] || dp[i-1][j-a[i-1]]);
else dp[i][j]=dp[i-1][j];
}
}
if (dp[n][nd]) {
return true;
}
}
return false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin>>n;
int sum=0;
for (int i = 0; i<n; i++) {
cin>>a[i];
sum+=a[i];
}
int hf=sum;
if (can(n, sum)) {
vector<int> ans;
for (int i = 1; i<=hf; i++) {
bool h=1;
for (int j = 0; j<n; j++) {
int dos=a[j];
sum-=a[j];
sum+=i;
a[j]=i;
if (!can(n,sum)) {
h=0;
a[j]=dos;
sum-=i;
sum+=dos;
break;
}
a[j]=dos;
sum-=i;
sum+=dos;
}
if (h) ans.push_back(i);
}
cout<<ans.size()<<'\n';
for (int i = 0; i<ans.size(); i++) cout<<ans[i]<<' ';
} else {
cout<<"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... |