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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <bitset>
#include <set>
#include <map>
typedef long long llong;
const int MAXN = 500 + 10;
const int MAXSUM = 500*500*2 + 10;
const int INF = 1e9;
int a[MAXN], n;
std::vector <int> values;
std::bitset <MAXSUM> bs, ans;
void getBitset(int missing)
{
bs.reset();
bs[MAXSUM / 2] = 1;
for (int i = 1 ; i <= n ; ++i)
{
if (i == missing) continue;
bs = ((bs << a[i]) | (bs >> a[i]));
}
}
void solve()
{
ans.set();
bs[MAXSUM / 2] = 1;
for (int i = 1 ; i <= n ; ++i)
{
bs = ((bs << a[i]) | (bs >> a[i]));
}
if (!bs[MAXSUM / 2])
{
std::cout << 0 << '\n';
return;
}
for (int i = 1 ; i <= n ; ++i)
{
getBitset(i);
ans &= bs;
}
for (int i = 1 ; i <= MAXSUM - MAXSUM/2 - 1 ; ++i)
{
if (ans[MAXSUM / 2 + i] || ans[MAXSUM / 2 - i])
{
values.push_back(i);
}
}
std::cout << values.size() << '\n';
for (const int &i : values)
{
std::cout << i << ' ';
}
std::cout << '\n';
}
void read()
{
std::cin >> n;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
solve();
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... |