제출 #566257

#제출 시각아이디문제언어결과실행 시간메모리
566257RealSnakeBootfall (IZhO17_bootfall)C++14
28 / 100
1094 ms31332 KiB
#include "bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define mod 1000000007

ofstream fout(".out");
ifstream fin(".in");

int b[250001], gg[501][250001];

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;
    cin >> n;
    int arr[n];
    int sum = 0;
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < sum; i++)
            b[i] = 0;
        swap(arr[k], arr[n - 1]);
        b[0] = 1;
        for(int i = 0; i < n; i++) {
            for(int j = sum; j >= arr[i]; j--) {
                b[j] += b[j - arr[i]];
                if(i == n - 1)
                    gg[k][j] = b[j - arr[i]];
            }
        }
        swap(arr[k], arr[n - 1]);
    }
    if(sum % 2 || !b[sum / 2]) {
        cout << 0;
        return 0;
    }
    vector<int> ans;
    for(int i = 1; i <= sum; i++) {
        bool bb = 1;
        for(int j = 0; j < n; j++) {
            int x = sum - arr[j] + i;
            if(i % 2 != arr[j] % 2 || x < 0 || !(b[x / 2] - gg[j][x / 2])) {
                bb = 0;
                break;
            }
        }
        if(bb)
            ans.push_back(i);
    }
    cout << ans.size() << "\n";
    for(int i : ans)
        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...