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 <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
#define ll long long
#define rint int32_t
const int siz = 250001;
rint main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int raw [n];
for (int i = 0; i < n; i++) cin >> raw[i];
bitset<siz> check(0);
check[0] = 1;
int checkSum = 0;
for (int i = 0; i < n; i++) {
check |= check<<raw[i];
checkSum += raw[i];
}
if (checkSum%2 == 1 or check[checkSum/2] == 0) {
cout << 0;
return 0;
}
bitset<siz> startToEnd [n];
startToEnd[0] = bitset<siz>(0);
startToEnd[0][0] = 1;
for (int i = 1; i < n; i++) {
startToEnd[i] = startToEnd[i-1]|(startToEnd[i-1]<<raw[i-1]);
}
bitset<siz> endToStart [n];
endToStart[n-1] = bitset<siz>(0);
endToStart[n-1][0] = 1;
for (int i = n-2; i >= 0; i--) {
endToStart[i] = endToStart[i+1]|(endToStart[i+1]<<raw[i+1]);
}
bitset<siz> even;
bitset<siz> uneven;
even.set();
uneven.set();
even[0] = 0;
bool evenKilled = false;
bool unevenKilled = false;
bitset<siz> cur;
int locSum;
for (int i = 0; i < n; i++) {
cur = startToEnd[i];
for (int j = i+1; j < n; j++) cur |= cur<<raw[j];
locSum = checkSum-raw[i];
if (locSum%2 == 0) {
even &= cur>>(locSum/2);
if (!unevenKilled) {
uneven &= 0;
unevenKilled = true;
}
}
else {
uneven &= cur>>(locSum/2+1);
if (!evenKilled) {
even &= 0;
evenKilled = true;
}
}
}
cout << even.count()+uneven.count() << endl;
for (int i = 0; i < siz; i++) {
if (even[i]) cout << i*2 << " ";
if (uneven[i]) cout << i*2+1 << " ";
}
int d = 0;
d++;
}
# | 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... |