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 suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
const ll mod=1e9+7;
const ll maxval=500*500;
ll cnt[maxval+5];
ll n,arr[505];
ll valid[maxval+5];
ll sum=0;
void add(ll x){
for(int i=maxval-x;i>=0;i--){
cnt[i+x]+=cnt[i];
cnt[i+x]%=mod;
}
}
void rem(ll x){
for(int i=0;i<=maxval-x;i++){
cnt[i+x]-=cnt[i];
cnt[i+x]+=mod;
cnt[i+x]%=mod;
}
}
void solve(){
cnt[0]=1;
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
sum+=arr[i];
add(arr[i]);
}
if(sum%2==1||cnt[sum/2]==0){
co 0;
return;
}
for(int i=1;i<=n;i++){
rem(arr[i]);
sum-=arr[i];
for(int j=0;j<=maxval;j++){
if(sum-2*j>0&&cnt[j]>0&&cnt[sum-j]>0) valid[sum-2*j]++;
}
sum+=arr[i];
add(arr[i]);
}
vector<ll>answers;
for(int i=1;i<=maxval;i++){
if(valid[i]==n) answers.push_back(i);
}
co answers.size()<<'\n';
for(auto i:answers){
co i<<' ';
}
}
int main()
{
suiii
int t=1;
// cin>>t;
while(t--){
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... |