#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) void(23)
#endif
template<typename T>
T power(T a, i64 b) {
T res = 1;
while(b) {
if(b & 1) {
res *= a;
}
a *= a;
b >>= 1;
}
return res;
}
constexpr i64 md = 232323233;
struct MInt {
i64 val;
MInt() : val(0) {}
template<typename T>
MInt(T v) {
if(-md <= v && v < md) {
val = v;
} else {
val = v % md;
}
if(val < 0) {
val += md;
}
}
i64 operator() () { return val; }
MInt operator+= (MInt rhs) {
if((val += rhs.val) >= md) {
val -= md;
}
return *this;
}
MInt operator-= (MInt rhs) {
if((val -= rhs.val) < 0) {
val += md;
}
return *this;
}
MInt operator*= (MInt rhs) {
val = (int)(1LL * val * rhs.val % md);
return *this;
}
MInt inv() {
return power(*this, md - 2);
}
MInt operator/= (MInt rhs) {
return *this *= rhs.inv();
}
bool operator== (MInt rhs) {
return val == rhs.val;
}
bool operator!= (MInt rhs) {
return val != rhs.val;
}
};
MInt operator+ (MInt lhs, MInt rhs) {
return lhs += rhs;
}
MInt operator- (MInt lhs, MInt rhs) {
return lhs -= rhs;
}
MInt operator* (MInt lhs, MInt rhs) {
return lhs *= rhs;
}
MInt operator/ (MInt lhs, MInt rhs) {
return lhs /= rhs;
}
std::ostream& operator<< (std::ostream& os, MInt v) {
return os << v();
}
std::string to_string(MInt x) {
return to_string(x());
}
using Z = MInt;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<int> A(N + 1);
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
}
bool bo[2] {};
for (int i = 0; i < N; ++i) {
bo[A[i] & 1] = true;
}
if (bo[0] && bo[1]) {
std::cout << "0\n";
return 0;
}
int sum = std::accumulate(A.begin(), A.end(), 0);
std::vector<Z> f(sum + 1);
f[0] = 1;
auto add = [&](int x) -> void {
for (int i = sum; i >= x; --i) {
f[i] += f[i - x];
}
};
auto del = [&](int x) -> void {
for (int i = x; i <= sum; ++i) {
f[i] -= f[i - x];
}
};
for (int i = 0; i < N; ++i) {
add(A[i]);
}
if ((sum & 1) || f[sum >> 1] == 0) {
std::cout << "0\n";
return 0;
}
std::vector<int> good(sum + 1, true);
for (int i = 0; i < N; ++i) {
del(A[i]);
for (int j = 1; j <= sum; ++j) {
int x = sum - A[i] + j;
if ((x & 1) || f[x >> 1] == 0) {
good[j] = false;
}
}
add(A[i]);
}
std::vector<int> ans;
for (int i = 1; i <= sum; ++i) {
if (good[i]) {
ans.emplace_back(i);
}
}
std::cout << ans.size() << '\n';
for (auto i : ans) {
std::cout << i << " \n"[i == ans.back()];
}
return 0;
}
# | 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... |