# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856374 | hgglmao | Bootfall (IZhO17_bootfall) | C++17 | 288 ms | 3156 KiB |
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 TASK "bootfall"
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ll> ill;
typedef pair<ll, int> lli;
typedef pair<ll, ll> pll;
const int MAX = 501;
const int SQMAX = 250001;
int n, a[MAX];
int sum;
ll dp[SQMAX];
bool check[SQMAX];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen(TASK ".inp", "r"))
{
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sum = accumulate(a + 1, a + n + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = sum - a[i]; j >= 0; --j)
dp[j + a[i]] += dp[j];
if (sum % 2 || !dp[sum / 2])
return cout << 0, 0;
fill(check + 1, check + sum + 1, 1);
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= sum - a[i]; ++j)
dp[j + a[i]] -= dp[j];
for (int cur = 1; cur <= sum; ++cur)
{
if ((sum - a[i] + cur) % 2)
{
check[cur] = 0;
continue;
}
int cur_req = (sum - a[i] + cur) / 2;
if (cur_req <= sum && dp[cur_req])
continue;
// if (cur_req - cur >= 0 && cur_req - cur <= sum && dp[cur_req - cur])
// continue;
check[cur] = 0;
}
for (int j = sum - a[i]; j >= 0; --j)
dp[j + a[i]] += dp[j];
}
cout << accumulate(check, check + sum + 1, 0) << '\n';
for (int i = 0; i <= sum; ++i)
if (check[i])
cout << i << ' ';
}
Compilation message (stderr)
# | 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... |