Submission #566392

#TimeUsernameProblemLanguageResultExecution timeMemory
566392shrimbBootfall (IZhO17_bootfall)C++17
100 / 100
474 ms2024 KiB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#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;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

// #define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 501;
const int maxs = maxn * maxn;

int dp[maxn * maxn];
bitset<maxn*maxn> ans;
int n, tot, ex=-1, total;
int a[maxn];

void add (int x) {
    for (int i = maxs ; i >= x ; i--) {
        dp[i] += dp[i - x];
        dp[i] %= mod;
    }
}

void rem (int x) {
    for (int i = x ; i <= maxs ; i++) {
        dp[i] =  (mod + dp[i] - dp[i-x]) % mod;
    }
}

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    dp[0] = 1;
    cin >> n;
    for (int i = 0 ; i < n ; i++) cin >> a[i], total += a[i], add(a[i]);
    for (int i = 0 ; i <= total ; i++) ans[i] = 1;
    if (!dp[total/2]) {
        cout << 0 << endl;
        return 0;
    }
    // cerr << "here\n";
    ans[0] = 0;
    for (int i = 0 ; i < n ; i++) {
        tot = total - a[i];
        rem(a[i]);
        ex = i;
        for (int j = 1 ; j <= total ; j++) {
            if ((tot+j)&1||!dp[(tot+j)/2]) {
                ans[j] = 0;
            }
        }
        add(a[i]);
    }
    cout << ans.count() << endl;
    for (int i = 0 ; i <= total ; i++) if (ans[i]) cout << i << " ";
}

Compilation message (stderr)

bootfall.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
#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...