#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> dx[N], ans;
void hbmt() {
cin >> n;
FOR(i, 1, n) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
ans.set();
dp[0] = 1;
FOR(i, 1, n) {
FORD(j, s[n], a[i]) {
dp[j] += dp[j - a[i]];
}
}
FORD(c, n, 1) {
ll sum = s[n] - a[c];
FOR(j, a[c], s[n]) {
dp[j] -= dp[j - a[c]];
}
FOR(i, 0, s[n]) {
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]];
}
}
cout << ans.count() << '\n';
FOR(i, 1, N - 1) {
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;
}
컴파일 시 표준 에러 (stderr) 메시지
bootfall.cpp: In function 'int main()':
bootfall.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen("hbmt.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | 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... |