# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92828 | SamAnd | Bootfall (IZhO17_bootfall) | C++17 | 620 ms | 124876 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>
using namespace std;
const int N = 502;
int n;
int a[N];
int m;
int u[N * N];
int uu[N * N];
bool t[N][N * N];
int main()
{
//freopen("input2.txt", "r", stdin);
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
m += a[i];
}
u[0] = 1;
for (int i = 1; i <= n; ++i)
{
for (int j = m; j >= 0; --j)
{
if (j + a[i] <= m)
u[j + a[i]] += u[j];
}
}
for (int i = 1; i <= n; ++i)
{
memcpy(uu, u, sizeof u);
for (int j = 0; j <= m; ++j)
{
if (j + a[i] <= m)
uu[j + a[i]] -= uu[j];
}
for (int j = 0; j <= m; ++j)
{
if (uu[j])
t[i][j] = true;
}
}
if ((m % 2) == 1 || !u[m / 2])
{
cout << 0 << endl;
return 0;
}
vector<int> ans;
for (int x = 1; x <= m; ++x)
{
bool z = true;
for (int i = 1; i <= n; ++i)
{
int y = (m - a[i] + x) / 2;
if (!((m - a[i] + x) % 2 == 0 && y <= m && t[i][y]))
{
z = false;
break;
}
}
if (z)
ans.push_back(x);
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); ++i)
cout << ans[i] << ' ';
cout << endl;
return 0;
}
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... |