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;
using ll = long long;
const ll inf = 1e18;
const int N = 250001, sq = 23;
int main() {
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, sum = 0;
cin >> n;
vector<int> a(n);
for (int &x: a) cin >> x;
vector<bitset<N>> without(sq);
bitset<N> bs; bs.set(0);
for (int x: a) bs |= bs << x;
for (int i = 0; i < sq; i++) {
without[i].set(0);
for (int j = 0; j < n; j++) {
if (i * sq <= j and j < (i + 1) * sq) continue;
without[i] |= without[i] << a[j];
}
}
vector<bitset<N>> without_2(n);
for (int i = 0; i < n; i++) {
sum += a[i];
without_2[i] = without[i / sq];
for (int j = i - i % sq; j < min(n, i - i % sq + sq); j++) {
if (i == j) continue;
without_2[i] |= without_2[i] << a[j];
}
}
vector<int> ans;
for (int i = 1; i < N; i++) {
if (sum % 2 or !bs[sum / 2]) continue;
sum += i;
bool ok = true;
for (int j = 0; j < n and ok; j++) {
sum -= a[j];
if (sum % 2 or !without_2[j][sum / 2]) ok = false;
sum += a[j];
}
sum -= i;
if (ok) ans.emplace_back(i);
}
cout << ans.size() << '\n';
for (int x: ans) cout << x << ' ';
}
# | 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... |