Submission #156165

#TimeUsernameProblemLanguageResultExecution timeMemory
156165andrewBootfall (IZhO17_bootfall)C++17
65 / 100
1064 ms3676 KiB
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 500;
const ll M = N * N;
const ll mod = 1e9 + 7;
const ll inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl;exit(0);}

ll dp[MAXN], kol[MAXN];

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    dp[0] = 1;

    ll n;

    cin >> n;

    vector <ll> a(n + 1);

    for(int i = 1; i <= n; i++)cin >> a[i];

    ll sc = 0;

    vector <ll> pref(n + 1);

    for(int i = 1; i <= n; i++){
        for(int j = pref[i - 1] + a[i]; j >= a[i]; j--)(dp[j] += dp[j - a[i]]) %= mod;
        pref[i] = pref[i - 1] + a[i];
    }

    sc = pref[n];

    if(sc % 2)vout(0);
    if(!dp[sc / 2])vout(0);

    ll S;

    for(int i = 1; i <= n; i++){
        for(int j = a[i]; j <= pref[n]; j++){
            dp[j] -= dp[j - a[i]];
            if(dp[j] < 0)dp[j] += mod;
        }

        for(int j = 1; j <= pref[n]; j++){
            S = sc - a[i] + j;
            if(S % 2 == 0 && dp[S / 2])kol[j]++;
        }

        for(int j = pref[n]; j >= a[i]; j--){
            (dp[j] += dp[j - a[i]]) %= mod;
        }
    }

    vector <ll> ans;

    for(int i = 1; i < MAXN; i++)if(kol[i] == n)ans.p_b(i);

    cout << ans.size() << "\n";

    for(auto i : ans)cout << i << " ";
    cout << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...