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 optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 125001;
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
bitset<N> dp;
int n;
cin >> n;
vector<int> a(n);
int total = 0;
dp.set(0);
for (int& i : a) {
cin >> i;
total += i;
dp |= dp << i;
}
if (total % 2 || !dp[total / 2]) {
cout << 0;
return 0;
}
vector<int> cnt(N * 2);
bitset<N> kek;
kek.set(0);
for (int i = 0; i < n; i++) {
dp = kek;
for (int j = i + 1; j < n; j++) {
dp |= dp << a[j];
}
kek |= kek << a[i];
for (int j = 0; j * 2 < total - a[i]; j++) {
cnt[abs(total - a[i] - 2 * j)] += dp[j];
}
}
vector<int> ans;
for (int i = 1; i < N * 2; i++) {
if (cnt[i] == n) {
ans.push_back(i);
}
}
cout << ans.size() << '\n';
for (int& i : ans) {
cout << i << ' ';
}
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... |