# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
173511 | AllMight | Bootfall (IZhO17_bootfall) | C++14 | 1077 ms | 736 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 <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
using namespace std;
const int N = 502;
int n;
int a[N];
int cnt[N * N];
vector <int> v;
void check(int ind)
{
vector <bool> knp(N * N, false);
knp[0] = true;
priority_queue <int> pq[2];
pq[0].push(0);
for (int i = 0, f = 0; i < n; i++, f = 1 - f) {
if (i == ind) {
f = 1 - f;
continue;
}
while (!pq[f].empty()) {
int tp = pq[f].top();
pq[f].pop();
pq[1 - f].push(tp);
if (!knp[tp + a[i]])
pq[1 - f].push(tp + a[i]);
knp[tp + a[i]] = true;
}
}
int sum;
if (pq[0].empty())
sum = pq[1].top();
else
sum = pq[0].top();
for (int i = 0; 2 * i < sum; i++) {
if (!knp[i]) continue;
int ans = sum - 2 * i;
cnt[ans]++;
if (ind == 0)
v.push_back(ans);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
vector <bool> knp(N * N, false);
knp[0] = true;
priority_queue <int> pq[2];
pq[0].push(0);
for (int i = 0, f = 0; i < n; i++, f = 1 - f) {
cin >> a[i];
while (!pq[f].empty()) {
int tp = pq[f].top();
pq[f].pop();
pq[1 - f].push(tp);
if (!knp[tp + a[i]])
pq[1 - f].push(tp + a[i]);
knp[tp + a[i]] = true;
}
}
int sum;
if (pq[0].empty())
sum = pq[1].top();
else
sum = pq[0].top();
if (sum % 2 || !knp[sum / 2]) {
cout << "0\n";
return 0;
}
for (int i = 0; i < n; i++)
check(i);
vector <int> ans;
for (int i = 0; i < v.size(); i++)
if (cnt[v[i]] == n)
ans.push_back(v[i]);
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << ' ';
cout << endl;
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... |