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>
#define N 400005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
using namespace std;
int cnt[N], a[N], dp[N];
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
}
dp[0]=1;
for (int i = 1; i <= n; i++){
for (int j = sum; j >= 0; j--){
if (dp[j]) dp[j+a[i]]=1;
}
}
if (!dp[sum/2] or sum%2) return cout << 0, 0;
for (int i = 1; i <= n; i++){
set<int> s;
for (int j = 0; j <= sum; j++){
dp[j]=0;
}
dp[0]=1;
for (int j = 1; j <= n; j++){
if (i == j) continue;
for (int k = sum; k >= 0; k--){
if (dp[k]) dp[k+a[j]]=1;
}
}
int sm = sum-a[i];
for (int j = 1; j < sum; j++){
if (dp[j]) s.insert(abs(2*j-sm));
}
for (auto j : s){
cnt[j]++;
}
}
vector<int> vec;
for (int i = 0; i < 3e5; i++){
if (cnt[i] == n) vec.pb(i);
}
cout << vec.size() << '\n';
for (auto i : vec){
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... |