This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Murad Eynizade */
#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 100001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);
#define MOD 1000000007
using namespace std;
bool f = false;
int dp[250005],sum , mx , can[250005];
vector<int>ans;
int main()
{
FAST_READ;
int n;
cin>>n;
int a[n];
for (int i = 0;i<n;i++)cin>>a[i] , sum += a[i];
sort(a,a+n);
dp[0] = 1;
for (int i = 0;i<n;i++)
for (int j = sum;j >= a[i];j--)
dp[j] += dp[j - a[i]];
if (sum % 2) {
cout<<0<<endl;
return 0;
}
for (int i = 1;i<sum;i++) {
if (dp[i] && i == sum / 2) {
f = true;
break;
}
}
if (!f) {
cout<<0<<endl;
return 0;
}
for (int no = 1;no<=n;no++) {
f = false;
mx = -1;
int oldsum = sum;
sum -= a[no - 1];
if (no == 1 || a[no - 1] != a[no - 2]) {
for (int i = a[no - 1];i<=oldsum;i++)
dp[i] -= dp[i - a[no - 1]];
}
for (int i = 1;i<=sum;i++) {
if (dp[i] && can[abs(i - (sum - i))] == no - 1) {
can[abs(i - (sum - i))] = no;
if (no == n)ans.push_back(abs(i - (sum - i)));
f = true;
}
}
if (!f) {
cout<<0<<endl;
return 0;
}
sum = oldsum;
if (no == n || a[no - 1] != a[no]) {
for (int i = sum;i>=a[no - 1];i--)
dp[i] += dp[i - a[no - 1]];
}
}
int sz = ans.size();
if (sz == 0)cout<<0<<endl;
else {
cout<<sz<<endl;
sort(ans.begin(),ans.end());
for (int i = 0;i<sz;i++) cout<<ans[i]<<" ";
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... |