# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
77124 | zetapi | Bootfall (IZhO17_bootfall) | C++14 | 754 ms | 3088 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"
using namespace std;
#define pb push_back
#define mp make_pair
#define ll int
#define int int
#define itr iterator
typedef pair<ll,ll> pii;
const ll MAX=3e5+9;
const ll LIM=3e5;
const ll mod=1e9+7;
bitset<500*500+9> bs;
set<ll> candidate;
ll N,sum,arr[500*500+9],dp[500*500+9];
void add(ll X)
{
sum+=X;
for(int A=500*500;A>=X;A--)
{
dp[A]+=dp[A-X];
if(dp[A]>=mod)
dp[A]-=mod;
}
return ;
}
void remove(ll X)
{
sum-=X;
for(int A=X;A<=500*500;A++)
{
dp[A]-=dp[A-X];
if(dp[A]<0)
dp[A]+=mod;
}
return ;
}
signed main()
{
scanf("%d",&N);
dp[0]=1;
for(int A=1;A<=N;A++)
{
scanf("%d",&arr[A]);
add(arr[A]);
}
if(sum%2 or (!dp[sum/2]))
return cout<<0,0;
for(int A=1;A<=sum;A++)
bs[A]=1;
int mn=sum;
for(int A=1;A<=N;A++)
{
remove(arr[A]);
mn=min(mn,sum);
for(int B=1;B<=sum;B++)
{
if((sum+B)%2 or (!dp[(sum+B)/2]))
bs[B]=0;
}
add(arr[A]);
}
vector<int> res;
for(int A=1;A<=mn;A++)
if(bs[A])
res.pb(A);
cout<<res.size()<<"\n";
for(auto A:res)
cout<<A<<" ";
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... |