Submission #993437

#TimeUsernameProblemLanguageResultExecution timeMemory
993437vjudge1Bootfall (IZhO17_bootfall)C++17
100 / 100
225 ms4556 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 530;
const int M = 250010;
int f[M], f2[M], cnt[M];

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

    if (sum % 2 == 0) {
        if (f[sum / 2] == 0) {
            cout << 0 << '\n';
            return 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= M; j++) {
            if (j >= a[i]) {
                f2[j] = (f[j] - f2[j - a[i]]);
            } else {
                f2[j] = f[j];
            }
        }

        int odd = (sum - a[i]) % 2;
        for (int j = odd; j <= M; j += 2) {
            int all = sum - a[i] + j;
            if (all % 2 == 0) {
                int h = all / 2;
                if (f2[h] != 0 || (h >= j && f2[h - j] != 0)) {
                    cnt[j]++;
                }
            }
        }
    }

    vector<int> save;
    for (int i = 1; i <= M; i++)
        if (cnt[i] == n)
            save.push_back(i);

    cout << save.size() << '\n';
    for (int x : save)
        cout << x << " ";

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