This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Bismillahi-rahmani-rahim
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf=1e9;
#define azdar priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
#define Lebap ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define pf push_front
#define pk pop_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
//#include <conio.h>
#include <climits>
const int N = 250000;
int n;
int a[505], cnt[N+505];
int dp[N+505], d[N+505];
vector<int> ans;
int main() {
Lebap;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int sum = 0;
for(int i=1;i<=n;i++) sum += a[i];
dp[0] = 1;
for(int i=1;i<=n;i++) {
for(int j=N;j>=0;j--) dp[j+a[i]] += dp[j];
}
if(sum%2!=0 || dp[sum/2]==0) return cout << "0", 0;
for(int i=1;i<=n;i++) {
memset(d,0,sizeof(d));
for(int j=0;j<=N;j++) {
d[j] += dp[j];
d[j+a[i]] -= d[j];
}
for(int j=0;j<=N;j++) {
if((sum-a[i]+j)%2==0 && sum-a[i]-j>=0 && d[(sum-a[i]-j)/2]!=0) cnt[j]++;
}
}
for(int i=1;i<=N;i++) if(cnt[i]==n) ans.push_back(i);
cout << ans.size() << endl;
for(auto i : ans) cout << i << " ";
}
# | 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... |