Submission #842701

#TimeUsernameProblemLanguageResultExecution timeMemory
842701zwezdinvBootfall (IZhO17_bootfall)C++17
65 / 100
1024 ms13272 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 501;
const int SZ = N * N + 100;
bitset<SZ> can[N], can_all;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& i : a) cin >> i;
    for (int i = 0; i < n; ++i) {
        can[i][0] = 1;
        for (int j = 0; j < n; ++j) {
            if (j != i) {
                can[i] |= can[i] << a[j];
            }
        }
    }
    can_all[0] = 1;
    for (int i = 0; i < n; ++i) {
        can_all |= can_all << a[i];
    }
    int sm = accumulate(a.begin(), a.end(), 0);
    vector<int> ans;
    for (int i = 1; i <= 2e5; ++i) {
        bool ok = sm % 2 == 0 && can_all[sm / 2];
        for (int j = 0; j < n && ok; ++j) {
            if ((sm - a[j] + i) % 2 != 0) ok = 0;
            int tar = (sm - a[j] + i) / 2;
            if (can[j][tar] || (tar >= i && can[j][tar - i])) {}
            else ok = 0;
        }
        if (ok) ans.push_back(i);
    }
    cout << ans.size() << '\n';
    for (auto i : ans) 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...