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;
int vis[500][2501];
int poss[2501];
int mark[501];
int sm[2501];
int a[500];
int N;
void dfs(int skip, int u = -1, int d = 0) {
if (-1 == u || skip != vis[u][d]) {
if (-1 ^ u) {
vis[u][d] = skip;
}
sm[d] = 1;
for (int j = u + 1; j < N; j ++) {
if (j ^ skip) {
dfs(skip, j, d + a[j]);
}
}
}
}
void solve() {
cin >> N;
for (int i = 0; i < N; i ++) {
cin >> a[i];
}
memset(vis, 0x3f, sizeof(vis));
int f = 1;
for (int i = 0; i <= N; i ++) {
memset(sm, 0, sizeof(sm));
int sum = 0;
for (int j = 0; j < N; j ++) {
if (i ^ j) {
sum += a[j];
}
}
dfs(i);
if (N == i) {
f = sm[sum / 2] && !(sum & 1);
continue;
}
for (int j = 0; j < 2501; j ++) {
if (sm[j] && j * 2 > sum ) {
poss[j * 2 - sum] ++;
}
}
}
if (0 == f) {
cout << 0 << endl;
return;
}
vector<int> ans;
for (int j = 1; j < 2501; j ++) {
if (poss[j] == N) {
ans.push_back(j);
}
}
cout << ans.size() << endl;
for (int i : ans) {
cout << i << ' ';
}
cout << endl;
}
int main() {
solve();
}
# | 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... |