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 pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 1e3 + 1, maxm = 4e3 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
ll n, x, y;
ll a[maxn], dp[maxn * maxn + 10], cnt[maxn * maxn + 10], cnt2[maxn * maxn + 10];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for (int j = maxn * maxn; j >= 0; --j){
if (dp[j] > 0){
dp[j + a[i]] += dp[j];
}
}
x += a[i];
}
if (x % 2 != 0 || (x % 2 == 0 && dp[x / 2] == 0)){
cout << 0 << '\n';
return 0;
}
for (int i = 1; i <= maxn * maxn; ++i){
cnt[i] = 1;
}
for (int i = 1; i <= n; ++i){
y = x - a[i];
for (int j = 0; j <= maxn * maxn; ++j){
if (j + a[i] <= maxn * maxn){
dp[j + a[i]] -= dp[j];
// dp[j + a[i]] = max(0ll, dp[j + a[i]]);
}
}
for (int j = 0; j <= maxn * maxn; ++j){
if (dp[j] > 0){
ll f = j, s = y - j;
ll rz = abs(f - s);
if (cnt[rz] == 1){
cnt2[rz] = 1;
}
}
}
for (int j = maxn * maxn; j >= 0; --j){
if (j + a[i] <= maxn * maxn - 1){
dp[j + a[i]] += dp[j];
}
}
for (int j = 1; j <= maxn * maxn; ++j){
cnt[j] = cnt2[j];
cnt2[j] = 0;
}
}
vector<int> v;
for (int i = 1; i <= maxn * maxn; ++i){
if (cnt[i] > 0){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
# | 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... |