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>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e2+1, lg = 20, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int dp[maxn*maxn], tmp[maxn*maxn], is[maxn*maxn];
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
int sum = 0;
rep(i,0,n) cin >> a[i];
int k = -1, f = 1;
rep(i,0,n){
int t = 0;
while(a[i]%2 == 0) t++, a[i] >>= 1, f *= 1 + (k == -1);
if(k == -1) k = t;
if(t - k) return cout << "0\n", 0;
sum += a[i];
}
rep(i,0,sum+1) is[i] = true;
dp[0] = 1;
rep(i,0,n) per(j,sum,a[i]) dp[j] += dp[j-a[i]], dp[j] -= dp[j]<mod?0:mod;
rep(k,0,n){
rep(i,0,sum+1) tmp[i] = dp[i];
rep(j,a[k],sum+1) tmp[j] -= tmp[j-a[k]], tmp[j] += tmp[j]<0?mod:0;
int bg = (sum - a[k] + 1)>>1;
rep(i,bg,sum+1) is[i-bg] &= (tmp[i] > 0);
rep(i,sum-bg+1,sum+1) is[i] = false;
}
// rep(k,0,n+1) rep(i,0,sum) er(k, i, dp[k][i]);
if((sum&1) || !dp[sum>>1]) return cout << "0\n", 0;
vector<int> ans;
rep(i,0,sum+1) if(is[i]) ans.pb((i<<1)+1);
cout << sz(ans) << '\n';
for(int c: ans) cout << c*f << ' ';
if(sz(ans)) cout << '\n';
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... |