#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int dp[N * N], cnt[N], a[N], n, tmp[N * N];
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
int s = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
s += a[i];
}
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = s; j >= 0; --j) if (a[i] <= j)
dp[j] += dp[j - a[i]];
}
if (dp[s / 2] == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= s; ++j) tmp[j] = dp[j];
tmp[a[i]]--;
for (int j = a[i] + 1; j <= s; ++j)
tmp[j] -= tmp[j - a[i]];
s -= a[i];
for (int j = 0; j <= s / 2; ++j) if (tmp[j] > 0) {
cnt[s - 2 * j]++;
}
s += a[i];
}
vector <int> res; res.clear();
for (int i = 1; i <= s; ++i) if (cnt[i] == n)
res.push_back(i);
cout << res.size() << endl;
for (int v : res) cout << v << ' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |