# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
344998 | _ani | Bootfall (IZhO17_bootfall) | C++17 | 0 ms | 0 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 <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;
const int N = 370;
vector<int> a, ans;
int SUM;
bitset<N* N> dp[N + 1][N + 1];
bitset<N* N> hrashq[N + 1];
int isok[N * N];
int main()
{
int n;
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
SUM += a[i];
}
bool skzb = false;
for (int jnj = 0; jnj < n; jnj++) {
auto b = a;
b.erase(b.begin() + jnj);
for (int i = 0; i < n - 1; i++) {
if (i - 1 < 0)
dp[jnj][i][0] = dp[jnj][i][b[i]] = 1;
else dp[jnj][i] = ((dp[jnj][i - 1] << b[i]) | dp[jnj][i - 1]);
}
}
for (int jnj = 0; jnj < n; jnj++)
{
for (int i = 0; i < n - 1; i++)
hrashq[jnj] |= dp[jnj][i];
if (hrashq[jnj][SUM / 2])skzb = true;
}
if (SUM % 2)skzb = false;
for (int i = 1; i <= N * N; i++) {
bool ok = true;
int cs = i + SUM;
for (int jnj = 0; jnj < n; jnj++) {
int ccs = cs - a[jnj];
if (ccs > N * N) {
ok = false;
break;
}
if (!hrashq[jnj][ccs / 2])
ok = false;
if (ccs % 2)ok = false;
}
if (ok && skzb)ans.push_back(i);
}
cout << ans.size() << '\n';
for (int a : ans)
cout << a << ' ';
return 0;
}