#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
inline void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
const ll N = 503;
ll n, a[N];
ll s[N];
ll dp[N * N];
bitset<N * N> dx[N], ans;
void hbmt() {
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
dp[0] = 1;
FOR(i, 1, n) {
FORD(j, s[n], a[i]) {
dp[j] += dp[j - a[i]];
adm(dp[j]);
}
}
bool ok = false;
FOR(i, 1, s[n] - 1) {
if(dp[i] != 0) ok = true;
}
if(!ok) {
cout << 0;
return;
}
ans.set();
FOR(c, 1, n) {
ll sum = s[n] - a[c];
FOR(j, a[c], s[n]) {
dp[j] -= dp[j - a[c]];
adm(dp[j]);
}
FOR(i, 1, s[n] - 1) {
ll sza = i, szb = sum - i;
if(dp[i] == 0) continue;
ll x = abs(sza - szb);
dx[c][x] = 1;
}
ans = (ans & dx[c]);
FORD(j, s[n], a[c]) {
dp[j] += dp[j - a[c]];
adm(dp[j]);
}
}
cout << ans.count() << '\n';
FOR(i, 0, N * N) {
if(ans[i] == 1) {
cout << i << ' ';
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen("hbmt.inp", "r")) {
freopen("hbmt.inp", "r", stdin);
freopen("hbmt.out", "w", stdout);
}
// t_test
hbmt();
return 0;
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("hbmt.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen("hbmt.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |