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"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
const int N = 505;
int n;
int a[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#ifdef JASPER
freopen("in1", "r", stdin);
#endif
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
int sz = accumulate(a + 1, a + 1 + n, 0);
sz *= 2;
vector <int> ans;
for (int x = 1; x <= sz; ++x) {
bool able = 1;
for (int k = 0; k <= n; ++k) {
swap(a[k], x);
vector <int> dp(sz + 5, 0);
dp[0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = sz; j >= a[i]; --j)
dp[j] |= dp[j - a[i]];
int tar = accumulate(a + 1, a + 1 + n, 0);
if (tar % 2 || (dp[tar / 2] == 0))
able = 0;
swap(a[k], x);
}
if (able) ans.push_back(x);
}
cout << (int) (ans.size()) << "\n";
for (int x : ans) cout << x << " ";
}
# | 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... |