This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define ld long double
#define all(_v) _v.begin(), _v.end()
#define sz(_v) (int)_v.size()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define veci vector <int>
#define vecll vector <ll>
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
int n;
int a[510];
ll dp[250010];
int sum;
void add(int x) {
sum += x;
for(int i = sum; i >= x; --i)
dp[i] += dp[i - x];
}
void del(int x) {
for(int i = x; i <= sum; ++i)
dp[i] -= dp[i - x];
sum -= x;
}
int go(int x) {
memset(dp, 0, sizeof(dp));
sum = 0;
dp[0] = 1;
a[n + 1] = x;
for(int i = 1; i <= n + 1; ++i)
add(a[i]);
for(int i = 1; i <= n + 1; ++i) {
del(a[i]);
if(sum & 1 || !dp[sum / 2])
return 0;
add(a[i]);
}
return 1;
}
void solve() {
cin >> n;
int s = 0;
for(int i = 1; i <= n; ++i) cin >> a[i], s += a[i];
veci ans;
for(int k = 1; k <= s; ++k)
if(go(k))
ans.pb(k);
cout << sz(ans) << '\n';
for(auto it : ans) cout << it << ' ';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
///cin >> T;
while(T--) solve(), cout << '\n';
return 0;
}
# | 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... |