# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377084 | ijxjdjd | Bootfall (IZhO17_bootfall) | C++14 | 128 ms | 33896 KiB |
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>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
const int MAXN = 500;
const int MAXA = 500;
stack<bitset<2*MAXN*MAXA>> st;
bitset<2*MAXN*MAXA> nt[MAXN];
bitset<2*MAXN*MAXA> tot;
bitset<2*MAXN*MAXA> pos;
vector<int> arr;
int S = 0;
void recur(int tl, int tr) {
if (tl == tr) {
nt[tl] = (st.top()>>(S-arr[tr]));
if (tr == arr.size()-1) {
tot = st.top()|(st.top() << (2*arr[tr]));
tot >>= S;
}
}
else {
int tm = (tl + tr)/2;
st.push(st.top());
for (int i = tl; i <= tm; i++) {
st.top() |= (st.top() << (2*arr[i]));
}
recur(tm+1, tr);
st.pop();
st.push(st.top());
for (int i = tm+1; i <= tr; i++) {
st.top() |= (st.top() << (2*arr[i]));
}
recur(tl, tm);
st.pop();
}
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int N;
cin >> N;
st.emplace();
st.top()[0] = 1;
pos.set();
FR(i, N) {
int a;
cin >> a;
S += a;
arr.push_back(a);
}
recur(0, N-1);
if (!tot[0]) {
cout << "0" << '\n';
return 0;
}
else {
FR(i, N) {
pos &= (nt[i]);
}
vector<int> res;
for (int i = 1; i < 2*MAXN*MAXA; i++) {
if (pos[i]) {
res.push_back(i);
}
}
cout << res.size() << '\n';
for (int r : res) {
cout << r << " ";
}
}
return 0;
}
Compilation message (stderr)
# | 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... |