제출 #915047

#제출 시각아이디문제언어결과실행 시간메모리
915047adaawfBootfall (IZhO17_bootfall)C++17
100 / 100
560 ms4176 KiB
#include <iostream>
using namespace std;
int a[505], f[250005], g[250005], dd[250005], mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, c = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        c += a[i];
    }
    f[0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            g[j] = f[j];
            f[j] = 0;
        }
        for (int j = 0; j <= c - a[i]; j++) {
            if (g[j] != 0) {
                f[j] += g[j];
                f[j + a[i]] += g[j];
                if (f[j] >= mod) f[j] -= mod;
            }
        }
    }
    if (c % 2 != 0 || f[c / 2] == 0) {
        cout << 0;
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            g[j] = f[j];
        }
        for (int j = a[i]; j <= c; j++) {
            g[j] -= g[j - a[i]];
            if (g[j] < 0) g[j] += mod;
        }
        int h = c - a[i];
        for (int j = 0; j <= c; j++) {
            if (h - j < 0 || h % 2 != j % 2 || g[(h - j) / 2] == 0) {
                dd[j] = 1;
            }
        }
    }
    int res = 0;
    for (int i = 0; i <= c; i++) {
        if (dd[i] == 0) {
            res++;
        }
    }
    cout << res << '\n';
    for (int i = 0; i <= c; i++) {
        if (dd[i] == 0) {
            cout << i << " ";
        }
    }
}
#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...