#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
const int maxn = 500, m = 250001;
int n;
int a[maxn], dp[m];
set<int> cur;
int s;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
dp[0] = 1;
for(int i = 0; i < n; i++){
cin >> a[i];
s += a[i];
for(int j = s - a[i]; j >= 0; j--){
dp[j + a[i]] += dp[j];
}
}
if(s % 2 || !dp[s / 2]){
cout << 0 << endl;
cout << endl;
return 0;
}
for(int i = 1; i < 3 * m / 2; i++) cur.insert(i);
for(int i = 0; i < n; i++){
for(int j = 0; j < s - a[i]; j++){
dp[j + a[i]] -= dp[j];
}
for(auto it = cur.begin(); it != cur.end();){
int x = *it;
it++;
if((s - a[i] + x) % 2 || !dp[(s - a[i] + x) / 2]) cur.erase(x);
}
for(int j = s - a[i]; j >= 0; j--){
dp[j + a[i]] += dp[j];
}
}
cout << cur.size() << endl;
for(auto it = cur.begin(); it != cur.end();){
int j = *it;
it++;
cout << j;
if(it != cur.end()) cout << " ";
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
17912 KB |
Output is correct |
2 |
Correct |
164 ms |
17900 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
159 ms |
17904 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |