Submission #1369061

#TimeUsernameProblemLanguageResultExecution timeMemory
1369061werityht1Bootfall (IZhO17_bootfall)C++20
100 / 100
203 ms3100 KiB
// ???????????????????????????????????????????????????????????
// ???????????????????????????????????????????????????????????
// ???????????????????????????????????????????????????????????
// ???????????????????????????????????????????????????????????
// ???????????????????????????????????????????????????????????
// ???????????????????????????????????????????????????????????
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define tos to_string
#define __lcm(x, y) ((x /__gcd(x, y)) * y)
// #pragma GCC optimize ("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define abs llabs
#define all(v) v.begin(), v.end()
const int N = 2E5 + 5, M = 1E5 + 5, LOG = 30;
const int inf = 1E18, MOD = 1E9 + 7, MOD1 = 998244353;

void solve() {
    int n;
    cin >> n;
    int a[n + 1]{}, sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }


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

    if (sum % 2 || dp[sum >> 1] == 0) {
        cout << "0\n";
        return;
    }

    bool cant[sum + 1]{};
    int ans = sum;
    for (int i = 1; i <= n; i++) {
        for (int j = a[i]; j <= sum; j++) {
            dp[j] -= dp[j - a[i]];
        }

        for (int j = 1; j <= sum; j++) {
            if (dp[(sum - a[i] + j) >> 1] == 0 || (sum - a[i] + j) % 2) {
                if (!cant[j]) {
                    ans--;
                    cant[j] = 1;
                }
            }
        }

        for (int j = sum; j >= a[i]; j--) {
            dp[j] += dp[j - a[i]];
        }
    }

    cout << ans << "\n";

    for (int i = 1; i <= sum; i++) {
        if (!cant[i]) {
            cout << i << ' ';
        }
    }
    cout << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ttt = 1;
    // cin >> ttt;
    while(ttt--) {
        solve();
    }
}
/*
*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...