# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700113 | messiuuuuu | Bootfall (IZhO17_bootfall) | C++17 | 1045 ms | 3208 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 "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 5e2 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 22071997;
int n;
int a[MAXN], sum = 0;
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
}
}
int dp[MAXN * MAXN], chk[MAXN * MAXN];
void add(int& a, int b)
{
a += b;
if (a >= MOD)
a -= MOD;
if (a < 0)
a += MOD;
}
void Solve()
{
if (sum % 2)
{
cout << 0;
return;
}
dp[0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = sum; j >= a[i]; j--)
{
add(dp[j], dp[j - a[i]]);
}
}
if (!dp[sum / 2])
{
cout << 0;
return;
}
for (int i = 1; i <= n; i++)
{
for (int j = a[i]; j <= sum; j++)
{
add(dp[j], -dp[j - a[i]]);
}
for (int j = 0; j <= (sum - a[i]) / 2; j++)
{
chk[sum - j - a[i] - j] += dp[j] > 0;
}
for (int j = sum; j >= a[i]; j--)
{
add(dp[j], dp[j - a[i]]);
}
}
vector<int> res;
for (int i = 0; i <= sum; i++)
if (chk[i] == n)
res.pb(i);
cout << res.size() << '\n';
for (int id : res)
cout << id << ' ';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
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... |