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;
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 502 * 502;
const ll inf = 1e18;
int dp[N];
int ok[N];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i=0;i<n;i++){
cin >> a[i];
}
sort(all(a));// useless :D
dp[0]=1;
for (int i=0;i<n;i++)
for (int j=N-1;j>=a[i];j--)
dp[j] += dp[j-a[i]];
int sum=0;
for_each(all(a),[&](int x){ sum+=x;});
bool flag = (sum%2==0 && dp[sum/2]);
if(!flag) return cout << 0, 0;
for (int i=0;i<n;i++){
// I will remove a[i]
sum -= a[i];
for (int j=a[i];j<N;j++)
dp[j] -= dp[j-a[i]];
for (int j=0;j<N;j++)
if (dp[j]&&2*j-sum >= 0) ok[2*j-sum]++;
for (int j=N-1;j>=a[i];j--)
dp[j] += dp[j-a[i]];
sum += a[i];
}
vector<int> ans;
for (int i=0;i<N;i++) if (ok[i]==n) ans.pb(i);
cout << sz(ans) << endl;
for (auto it : ans){
cout << it << ' ';
}
cout << endl;
}
# | 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... |