# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
229888 | pedroslrey | Bootfall (IZhO17_bootfall) | C++14 | 935 ms | 3568 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.
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using lli = long long int;
#define debug(args...) fprintf(stderr, args)
#define pb push_back
#define fi first
#define se second
#define all(xs) xs.begin(), xs.end()
const int INF = 1e9;
int dp[510*510];
int xs[510];
int marc[510*510];
inline void add(int i, int s) {
for (int k = s; k >= 0; --k) {
lli tmp = 1LL*dp[k + xs[i]] + dp[k];
dp[k + xs[i]] = tmp%INF;
}
}
inline void sub(int i, int s) {
for (int k = 0; k <= s; ++k) {
lli tmp = 1LL*dp[k + xs[i]] - dp[k];
dp[k + xs[i]] = tmp%INF;
}
}
void init_dp(int n, int s) {
dp[0] = 1;
for (int i = 1; i <= n; ++i)
add(i, s);
}
void solve(int n) {
int s = 0;
for (int i = 1; i <= n; ++i)
s += xs[i];
init_dp(n, s);
if (dp[s/2] == 0 || s%2 == 1) {
printf("0\n");
return;
}
for (int i = 1; i <= n; ++i) {
sub(i, s);
for (int k = 1; k <= s; ++k) {
if ((s - xs[i] + k)%2 == 1) marc[k] = 0;
if (s - xs[i] - k < 0) continue;
else if (dp[(s - xs[i] - k)/2]) ++marc[k];
}
add(i, s);
}
vector<int> ans;
for (int k = 1; k <= s; ++k)
if (marc[k] == n) ans.pb(k);
printf("%d\n", (int) ans.size());
for (int a: ans)
printf("%d ", a);
printf("\n");
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &xs[i]);
solve(n);
}
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... |