# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
650286 | sofija6 | Bootfall (IZhO17_bootfall) | C++14 | 756 ms | 4180 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 ll long long
#define MAXN 510
#define MAXS 250010
#define MOD 1000000007
using namespace std;
ll dp[MAXS],sum,a[MAXN];
bool yes[MAXS];
void Add(ll x)
{
for (ll i=MAXS-5;i>=x;i--)
dp[i]=(dp[i]+dp[i-x])%MOD;
}
void Remove(ll x)
{
for (ll i=x;i<=MAXS-5;i++)
dp[i]=(dp[i]-dp[i-x]+MOD)%MOD;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
dp[0]=1;
for (ll i=1;i<=n;i++)
{
cin >> a[i];
sum+=a[i];
}
for (ll i=1;i<=n;i++)
Add(a[i]);
if (sum&1 || !dp[sum/2])
{
cout << 0 << "\n";
return 0;
}
for (ll i=1;i<MAXS;i++)
yes[i]=true;
for (ll i=1;i<=n;i++)
{
Remove(a[i]);
for (ll j=1;j<MAXS;j++)
{
if (!yes[j])
continue;
if ((sum+j-a[i])&1 || !dp[(sum+j-a[i])/2])
yes[j]=false;
}
Add(a[i]);
}
vector<ll> ans;
for (ll i=1;i<MAXS;i++)
{
if (yes[i])
ans.push_back(i);
}
cout << ans.size() << "\n";
for (ll i=0;i<ans.size();i++)
cout << ans[i] << " ";
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... |