제출 #947606

#제출 시각아이디문제언어결과실행 시간메모리
947606PringBootfall (IZhO17_bootfall)C++17
100 / 100
934 ms17748 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt")
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;

const int MXN = 250005;
int n, a[MXN];
int sum;
bitset<MXN> ans, b, c;
bitset<MXN> p[505];

bool check() {
    if (sum & 1) return false;
    ans.reset();
    ans[0] = true;
    FOR(i, 0, n) ans |= (ans << a[i]);
    return ans[sum / 2];
}

void miku() {
    cin >> n;
    FOR(i, 0, n) cin >> a[i];
    FOR(i, 0, n) sum += a[i];
    if (!check()) {
        cout << 0 << '\n' << '\n';
        return;
    }
    ans.set();
    p[0][0] = 1;
    FOR(i, 0, n) p[i + 1] = p[i] | (p[i] << a[i]);
    FOR(i, 0, n) {
        c.reset();
        b = p[i];
        FOR(j, i + 1, n) b |= (b << a[j]);
        FOR(j, 0, sum - a[i] + 1) if (b[j]) c[abs(sum - a[i] - 2 * j)] = true;
        ans &= c;
    }
    cout << ans.count() << '\n';
    FOR(i, 0, MXN) if (ans[i]) cout << i << ' ';
    cout << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    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...