제출 #1323760

#제출 시각아이디문제언어결과실행 시간메모리
13237601otaBootfall (IZhO17_bootfall)C++20
100 / 100
572 ms1120 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC target("sse4,avx2,fma,avx")
using namespace std;

#define endl "\n"
#define entire(x) (x).begin(), (x).end()

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n; cin >> n;
    vector<int> a(n);
    bitset<250001> ans; ans[0] = 1;
    for (int i = 0; i < n; i++){
        cin >> a[i]; ans |= ans << a[i];
    }

    int sum = accumulate(entire(a), 0ll);
    if (sum & 1 or !ans[sum >> 1]) { cout << 0 << endl; return 0; }
    
    bitset<250001> cur, good, done; ans.reset(); done[0] = 1;
    for (int i = 1; i <= sum; i++) ans[i] = 1;

    for (int idx = 0; idx < n; idx++){
        cur |= done;
        for (int i = idx + 1; i < n; i++) cur |= cur << a[i];
        for (int i = a[idx] & 1; i <= sum - a[idx]; i += 2) if (ans[i]) {
            int target = (sum - a[idx] + i);
            if (target & 1) continue; target >>= 1;
            good[i] = cur[target] | cur[target - i];
        } ans &= good; done |= done << a[idx];
        if (idx != n-1) cur.reset(), good.reset();
    }

    cout << ans.count() << endl;
    for (int i = 1; i <= sum; i++) if (ans[i]) cout << i << " ";

    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...