# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36136 | aome | Bootfall (IZhO17_bootfall) | C++14 | 376 ms | 6972 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 = 505;
int n, a[N], sum[N];
int f[2][N * N];
int g[N * N];
int cnt[N * N];
vector<int> res;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i], sum[i] = sum[i - 1] + a[i];
}
f[0][0] = 1;
for (int i = 0; i < n; ++i) {
bool x = i & 1;
for (int j = 0; j <= sum[i]; ++j) {
f[x ^ 1][j + a[i + 1]] += f[x][j];
f[x ^ 1][j] += f[x][j];
f[x][j] = 0;
}
}
if (sum[n] & 1 || !f[n & 1][sum[n] / 2]) {
cout << 0; return 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= sum[n]; ++j) {
g[j] = f[n & 1][j]; if (j >= a[i]) g[j] -= g[j - a[i]];
}
for (int j = 0; sum[n] - a[i] - j - j >= 0; ++j) {
if (g[j]) cnt[sum[n] - a[i] - j - j]++;
}
}
for (int i = 1; i <= sum[n]; ++i) {
if (cnt[i] == n) res.push_back(i);
}
printf("%d\n", res.size());
for (int i = 0; i < res.size(); ++i) printf("%d ", res[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... |