# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37447 | HardNut | Bootfall (IZhO17_bootfall) | C++14 | 1000 ms | 3968 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 = 250005;
const int mod = 1e9 + 7;
typedef long long ll;
int n, a[505], sum;
vector<int> vec;
int ans[N];
int dp[N];
void add(int v) {
for (int i = sum; i >= 0; i--) {
dp[i + v] += dp[i];
dp[i + v] %= mod;
}
sum += v;
}
void del(int v) {
sum -= v;
for (int i = 0; i <= sum; i++) {
dp[i + v] = (dp[i + v] - dp[i] + mod) % mod;
}
}
int main() {
scanf("%d", &n);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
add(a[i]);
}
if (sum % 2 == 1) {
cout << 0;
return 0;
}
for (int i = 1; i <= sum; i++) {
ans[i] = 1;
}
if (!dp[sum / 2]) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; i++) {
del(a[i]);
for (int j = 1; j <= N; j++) {
if ((sum + j) % 2) {
ans[j] = 0;
continue;
}
if (!dp[(sum + j) / 2]) {
ans[j] = 0;
}
}
add(a[i]);
}
int cnt = 0;
for (int i = 1; i <= sum; i++) {
cnt += ans[i];
}
printf("%d\n", cnt);
for (int i = 1; i <= sum; i++)
if (ans[i])
printf("%d ", 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... |