이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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()
{
ios_base::sync_with_stdio(false);
dp[0]=1;
cin>>N;
for(int A=1;A<=N;A++)
{
cin>>arr[A];
add(arr[A]);
}
if(sum%2 or (!dp[sum/2]))
return cout<<0,0;
for(int A=1;A<=sum;A++)
candidate.insert(A);
for(int A=1;A<=N;A++)
{
remove(arr[A]);
vector<int> lol;
for(auto B:candidate)
{
if(B>sum or (sum+B)%2 or (!dp[(sum+B)/2]))
lol.pb(B);
}
for(auto B:lol)
candidate.erase(B);
add(arr[A]);
}
cout<<candidate.size()<<"\n";
for(auto A:candidate)
cout<<A<<" ";
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... |