제출 #682676

#제출 시각아이디문제언어결과실행 시간메모리
682676opPOBootfall (IZhO17_bootfall)C++17
100 / 100
763 ms2812 KiB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 998244353;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 250001;

void backpack(bitset<N> &can, vec<int> &a, int l, int r)
{
    can.reset();
    can[0] = 1;
    for (int i = l; i <= r; i++) can |= can << a[i];
}

void solve()
{
    int n;
    cin >> n;
    vec<int> a(n + 1);
    int s = 0;
    for (int i = 1; i <= n; i++) cin >> a[i], s += a[i];
    bitset<N> base, start, end;
    backpack(base, a, 1, n);
    if (!base[s / 2])
    {
        cout << 0;
        return;
    }
    backpack(start, a, 1, n / 2);
    backpack(end, a, n / 2 + 1, n);
    vec<int> cnt(500 * n + 1);
    for (int i = 1; i <= n; i++)
    {
        bitset<N> can;
        if (i <= n / 2)
        {
            can = end;
            for (int j = 1; j <= n / 2; j++) if (j != i) can |= can << a[j];
        }
        else
        {
            can = start;
            for (int j = n / 2 + 1; j <= n; j++) if (j != i) can |= can << a[j];
        }
        int from = (s - a[i]) % 2 ? 1 : 2;
        for (int j = from; j <= 500 * n; j += 2)
        {
            if (can[(s - a[i] + j) / 2]) cnt[j]++;
        }
    }
    vec<int> ans;
    for (int i = 1; i <= 500 * n; i++) if (cnt[i] == n) ans.pb(i);
    cout << sz(ans) << "\n";
    for (int &x : ans) cout << x << " ";
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    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...