#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
const ll MOD = 1e9+7;
const ll INF = 2e18;
struct SparseTable{
vector<vector<ll>> t; ll n;
vector<ll> log;
ll func(ll a, ll b){
return min(a, b);
}
void init(ll N, vector<ll> &a){
n=N; log.resize(n+1);
for (ll i=2; i<=n; i++) log[i]=log[i/2]+1;
t.resize(log[N]+1, vector<ll>(n));
t[0]=a;
for (ll i=1; i<=log[n]; i++){
for (ll j=0; j<=n-(1<<i); j++){
t[i][j]=func(t[i-1][j], t[i-1][j+(1<<(i-1))]);
}
}
}
ll query(ll l, ll r){
ll lg = log[r-l+1];
return func(t[lg][l], t[lg][r-(1<<lg)+1]);
}
};
void solve(){
ll n; cin >> n;
vector<ll> a(n);
bitset<500*600> pos, pos2;
bitset<500*600> dp;
ll sm=0;
for (ll i=0; i<n; i++){
cin >> a[i]; sm+=a[i];
dp = (dp<<a[i])|dp;
dp.set(a[i]);
}
if (!(dp[sm/2] and sm%2==0)){
cout << 0 << ln; return;
}
for (ll i=1; i<=250000; i++) pos.set(i);
for (ll i=0; i<n; i++){
dp.reset();
pos2.reset();
ll sum=0;
for (ll j=0; j<n; j++){
if (i==j) continue;
sum+=a[j];
dp=(dp<<a[j])|dp;
dp.set(a[j]);
}
for (ll j=1; j<=250000; j++){
if (dp[j]) pos2.set(abs(j-(sum-j)));
}
pos=pos&pos2;
}
vector<ll> res;
for (ll i=1; i<=250000; i++){
if (pos[i]) res.push_back(i);
}
cout << res.size() << ln;
for (auto ch:res) cout << ch << " ";
cout << ln;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
auto start = chrono::high_resolution_clock::now();
ll t=1;
// cin >> t;
while (t--) solve();
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
}
# | 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... |