# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
700119 | fdnfksd | Bootfall (IZhO17_bootfall) | C++14 | 395 ms | 3420 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 task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 5e2 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 22071997;
int n;
int a[MAXN], sum = 0;
void Input()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
}
}
int dp[MAXN * MAXN], chk[MAXN * MAXN];
void Solve()
{
if (sum % 2)
{
cout << 0;
return;
}
dp[0] = 1;
for (int i = 1; i <= n; i++)
{
for (int j = sum; j >= a[i]; j--)
{
dp[j]+=dp[j - a[i]];
if(dp[j]>=MOD) dp[j]-=MOD;
}
}
if (!dp[sum / 2])
{
cout << 0;
return;
}
for (int i = 1; i <= n; i++)
{
for (int j = a[i]; j <= sum; j++)
{
dp[j]-= dp[j - a[i]];
if(dp[j]<0) dp[j]+=MOD;
}
for (int j = 0; j <= (sum - a[i]) / 2; j++)
{
chk[sum - j - a[i] - j] += dp[j] > 0;
}
for (int j = sum; j >= a[i]; j--)
{
dp[j]+=dp[j - a[i]];
if(dp[j]>=MOD) dp[j]-=MOD;
}
}
vector<int> res;
for (int i = 0; i <= sum; i++)
if (chk[i] == n)
res.pb(i);
cout << res.size() << '\n';
for (int id : res)
cout << id << ' ';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(task".INP","r"))
{
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
Input();
Solve();
}
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... |