This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 271;
bool dp[2][maxn*maxn];
bitset<maxn*maxn> ans;
int n, tot, ex=-1, total;
int a[maxn];
void rec () {
for (int i = n ; i >= 0 ; i--) {
for (int j = 0 ; j <= total ; j++) {
if (i == n) dp[0][j] = j == 0;
else if (i == ex) dp[0][j] = dp[1][j];
else dp[0][j] = dp[1][j] || (j - a[i] < 0 ? 0 : dp[1][j - a[i]]);
}
swap(dp[0], dp[1]);
}
swap(dp[0], dp[1]);
// if (sm < 0) return 0;
// if (i == n) return sm == 0;
// if (i == ex) return rec(i + 1, sm);
// if (dp[i][sm] != -1) return dp[i][sm];
// return dp[i][sm] = rec(i + 1, sm) | rec(i + 1, sm - a[i]);
}
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0 ; i < n ; i++) cin >> a[i], total += a[i];
for (int i = 0 ; i <= total ; i++) ans[i] = 1;
rec();
if (!dp[0][total/2]) {
cout << 0 << endl;
return 0;
}
// cerr << "here\n";
ans[0] = 0;
for (int i = 0 ; i < n ; i++) {
tot = total - a[i];
ex = i;
rec();
for (int j = 1 ; j <= total ; j++) {
if ((tot+j)&1||!dp[0][(tot+j)/2]) {
ans[j] = 0;
}
}
}
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |