Submission #522856

# Submission time Handle Problem Language Result Execution time Memory
522856 2022-02-06T05:24:51 Z Nursik Bootfall (IZhO17_bootfall) C++14
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair

const ll maxn = 271, maxm = 3e5 + 1,  maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;

using namespace std;

int n, x, y;
int a[maxn], is[maxn * maxn], dp2[maxn * maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    dp2[0] = 1;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        x += a[i];
        for (int j = x; j >= 0; --j){
            if (dp2[j] > 0){
                dp2[j + a[i]] |= dp2[j];
            }
        }
    }
    if (x % 2 != 0){
        cout << 0;
        return 0;
    }
    if (x % 2 == 0 && dp2[x / 2] == 0){
        cout << 0;
        return 0;
    }
    for (int i = 0; i <= x; ++i){
        is[i] = 1;
    }
    for (int i = 1; i <= n; ++i){
        int dp[x + 1], is2[x + 1];
        for (int j = 0; j <= x; ++j){
            dp[j] = 0, is2[j] = 0;
        }
        dp[0] = 1;
        y = x - a[i];
        ll sumik = 0;
        for (int j = 1; j <= n; ++j){
            if (i != j){
                for (int k = sumik; k >= 0; --k){
                    if (dp[k] > 0 && k + a[j] <= y){
                        dp[k + a[j]] |= dp[k];
                    }
                }
                sumik += a[j];
            }
        }
        for (int k = 0; k <= y; ++k){
            ll z = y - k;
            if (z > 0 && min(dp[z], dp[k]) == 1){
                ll rz = abs(z - k);
                if (is[rz] == 1){
                    is2[rz] = 1;
                }
            }
        }
        for (int k = 0; k <= y; ++k){
            is[k] = is2[k];
        }
    }
    vector<int> v;
    for (int i = 1; i <= x; ++i){
        if (is[i] > 0){
            v.pb(i);
        }
    }
    cout << v.size() << '\n';
    for (auto it : v){
        cout << it << " ";
    }
}
/*
*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -