This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Bismillahir-Rahmanir-Rahim
# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
# define deb(x) cerr << #x << " = " << x << endl;
# define pll pair <ll, ll>
# define pii pair <int, int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 5e2 + 3;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, a[maxn], sum;
int dp[maxn * maxn];
bitset <maxn * maxn> ok;
void add (int x) {
sum += x;
for (int i = sum - x; i >= 0; --i) {
dp[i + x] += dp[i];
}
}
void del (int x) {
for (int i = x; i <= sum; ++i) {
dp[i] -= dp[i - x];
}
sum -= x;
}
void ma1n (/* SABR */) {
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
add(a[i]);
}
if (sum & 1 || !dp[sum / 2]) {
cout << 0 << nl;
}
else {
for (int x = 1; x <= 250000; ++x) {
ok[x] = 1;
}
for (int i = 1; i <= n; ++i) {
del(a[i]);
for (int x = 1; x <= 250000; ++x){
if ((sum + x) & 1 || !dp[(sum + x) / 2]) {
ok[x] = 0;
}
}
add(a[i]);
}
cout << ok.count() << nl;
for (ll x = ok._Find_first(); x <= 250000; x = ok._Find_next(x)) {
cout << x << ' ';
}
cout << nl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test) {
// cout << "Case " << test << ":" << '\n';
ma1n();
}
return 0;
}
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist | BbIWEJI 3A TObOU!!!
# | 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... |