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>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
#define pss pair<line*, line*>
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll inf = 1e18;
const int MOD = 1e9 + 7;
const int dx[] = {-1, +1, -2, +2, -2, +2, -1, +1};
const int dy[] = {-2, -2, -1, -1, +1, +1, +2, +2};
int const N = 125001;
int const M = 2e6;
bitset<N> dp[505];
int main() {
#ifdef Mask
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
int sum = 0;
int a[n + 1];
for (int i = 1; i <= n; i++)
cin >> a[i], sum += a[i];
for (int del = 0; del <= n; del++) {
dp[del][0] = 1;
for (int i = 0; i < n; i++) {
if (i + 1 == del)
continue;
dp[del] |= (dp[del] << a[i + 1]);
}
}
vector<int> ans;
for (int k = 1; k <= 125000; k++) {
bool ok = true;
for (int del = 0; del <= n; del++) {
int all = sum + k;
if (del == 0) all -= k;
else all -= a[del];
if (all % 2 == 1) {
ok = false;
break;
}
int need = all / 2;
if (need > N) {
ok = false;
break;
}
if (dp[del][need] == 0) {
ok = false;
break;
}
}
if (ok == true)
ans.pb(k);
}
cout << ans.size() << endl;
for (int to : ans)
cout << to << " ";
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... |