#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAX_N = 505;
const int MAX_SUM = 500 * 500 + 5;
int a[MAX_N], dp[MAX_SUM], aux[MAX_SUM], cntOkWith[MAX_SUM];
int main() {
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
int n;
cin >> n;
int sum = 0;
dp[0] = 1;
for(int i = 0; i < n; i++) {
cin >> a[i];
for(int j = sum; j >= 0; j--) {
dp[j + a[i]] += dp[j];
}
sum += a[i];
}
if(sum % 2 != 0 || dp[sum / 2] == 0) {
cout << 0 << endl;
return 0;
}
for(int i = 0; i < n; i++) {
for(int j = 0; j <= sum; j++) {
aux[j] = dp[j];
}
for(int j = a[i]; j <= sum; j++) {
aux[j] -= aux[j - a[i]];
}
for(int j = 1; j <= sum; j++) {
int newSum = sum - a[i] + j;
if(newSum % 2 == 0 && aux[newSum / 2] != 0) {
cntOkWith[j]++;
}
}
}
vector< int > ans;
for(int i = 1; i <= sum; i++) {
if(cntOkWith[i] == n) {
ans.push_back(i);
}
}
cout << ans.size() << endl;
for(int x : ans) {
cout << x << " ";
}
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
4948 KB |
Output is correct |
11 |
Correct |
0 ms |
4948 KB |
Output is correct |
12 |
Correct |
0 ms |
4948 KB |
Output is correct |
13 |
Correct |
0 ms |
4948 KB |
Output is correct |
14 |
Correct |
0 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
4948 KB |
Output is correct |
17 |
Correct |
0 ms |
4948 KB |
Output is correct |
18 |
Correct |
0 ms |
4948 KB |
Output is correct |
19 |
Correct |
0 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
4948 KB |
Output is correct |
11 |
Correct |
0 ms |
4948 KB |
Output is correct |
12 |
Correct |
0 ms |
4948 KB |
Output is correct |
13 |
Correct |
0 ms |
4948 KB |
Output is correct |
14 |
Correct |
0 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
4948 KB |
Output is correct |
17 |
Correct |
0 ms |
4948 KB |
Output is correct |
18 |
Correct |
0 ms |
4948 KB |
Output is correct |
19 |
Correct |
0 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
4948 KB |
Output is correct |
21 |
Correct |
0 ms |
4948 KB |
Output is correct |
22 |
Correct |
0 ms |
4948 KB |
Output is correct |
23 |
Correct |
0 ms |
4948 KB |
Output is correct |
24 |
Correct |
0 ms |
4948 KB |
Output is correct |
25 |
Correct |
0 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
0 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
0 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
4948 KB |
Output is correct |
11 |
Correct |
0 ms |
4948 KB |
Output is correct |
12 |
Correct |
0 ms |
4948 KB |
Output is correct |
13 |
Correct |
0 ms |
4948 KB |
Output is correct |
14 |
Correct |
0 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
4948 KB |
Output is correct |
17 |
Correct |
0 ms |
4948 KB |
Output is correct |
18 |
Correct |
0 ms |
4948 KB |
Output is correct |
19 |
Correct |
0 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
4948 KB |
Output is correct |
21 |
Correct |
0 ms |
4948 KB |
Output is correct |
22 |
Correct |
0 ms |
4948 KB |
Output is correct |
23 |
Correct |
0 ms |
4948 KB |
Output is correct |
24 |
Correct |
0 ms |
4948 KB |
Output is correct |
25 |
Correct |
0 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
0 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
0 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
16 ms |
5088 KB |
Output is correct |
38 |
Correct |
19 ms |
5088 KB |
Output is correct |
39 |
Correct |
63 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5088 KB |
Output is correct |
41 |
Correct |
63 ms |
4948 KB |
Output is correct |
42 |
Correct |
29 ms |
5088 KB |
Output is correct |
43 |
Correct |
53 ms |
5220 KB |
Output is correct |
44 |
Correct |
49 ms |
5220 KB |
Output is correct |
45 |
Correct |
53 ms |
5220 KB |
Output is correct |
46 |
Correct |
33 ms |
4948 KB |
Output is correct |
47 |
Correct |
26 ms |
5088 KB |
Output is correct |
48 |
Correct |
59 ms |
5220 KB |
Output is correct |
49 |
Correct |
59 ms |
5088 KB |
Output is correct |
50 |
Correct |
29 ms |
5088 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
63 ms |
5220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
4948 KB |
Output is correct |
11 |
Correct |
0 ms |
4948 KB |
Output is correct |
12 |
Correct |
0 ms |
4948 KB |
Output is correct |
13 |
Correct |
0 ms |
4948 KB |
Output is correct |
14 |
Correct |
0 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
4948 KB |
Output is correct |
17 |
Correct |
0 ms |
4948 KB |
Output is correct |
18 |
Correct |
0 ms |
4948 KB |
Output is correct |
19 |
Correct |
0 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
4948 KB |
Output is correct |
21 |
Correct |
0 ms |
4948 KB |
Output is correct |
22 |
Correct |
0 ms |
4948 KB |
Output is correct |
23 |
Correct |
0 ms |
4948 KB |
Output is correct |
24 |
Correct |
0 ms |
4948 KB |
Output is correct |
25 |
Correct |
0 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
0 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
0 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
16 ms |
5088 KB |
Output is correct |
38 |
Correct |
19 ms |
5088 KB |
Output is correct |
39 |
Correct |
63 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5088 KB |
Output is correct |
41 |
Correct |
63 ms |
4948 KB |
Output is correct |
42 |
Correct |
29 ms |
5088 KB |
Output is correct |
43 |
Correct |
53 ms |
5220 KB |
Output is correct |
44 |
Correct |
49 ms |
5220 KB |
Output is correct |
45 |
Correct |
53 ms |
5220 KB |
Output is correct |
46 |
Correct |
33 ms |
4948 KB |
Output is correct |
47 |
Correct |
26 ms |
5088 KB |
Output is correct |
48 |
Correct |
59 ms |
5220 KB |
Output is correct |
49 |
Correct |
59 ms |
5088 KB |
Output is correct |
50 |
Correct |
29 ms |
5088 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
63 ms |
5220 KB |
Output is correct |
53 |
Correct |
46 ms |
5220 KB |
Output is correct |
54 |
Correct |
66 ms |
5220 KB |
Output is correct |
55 |
Correct |
166 ms |
5416 KB |
Output is correct |
56 |
Correct |
59 ms |
5220 KB |
Output is correct |
57 |
Correct |
139 ms |
5416 KB |
Output is correct |
58 |
Correct |
73 ms |
5220 KB |
Output is correct |
59 |
Correct |
93 ms |
5416 KB |
Output is correct |
60 |
Correct |
19 ms |
4948 KB |
Output is correct |
61 |
Correct |
116 ms |
5416 KB |
Output is correct |
62 |
Correct |
106 ms |
5416 KB |
Output is correct |
63 |
Correct |
136 ms |
5416 KB |
Output is correct |
64 |
Correct |
123 ms |
5416 KB |
Output is correct |
65 |
Correct |
59 ms |
4948 KB |
Output is correct |
66 |
Correct |
59 ms |
5088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
4948 KB |
Output is correct |
2 |
Correct |
0 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
4948 KB |
Output is correct |
4 |
Correct |
0 ms |
4948 KB |
Output is correct |
5 |
Correct |
0 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
4948 KB |
Output is correct |
7 |
Correct |
0 ms |
4948 KB |
Output is correct |
8 |
Correct |
0 ms |
4948 KB |
Output is correct |
9 |
Correct |
0 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
4948 KB |
Output is correct |
11 |
Correct |
0 ms |
4948 KB |
Output is correct |
12 |
Correct |
0 ms |
4948 KB |
Output is correct |
13 |
Correct |
0 ms |
4948 KB |
Output is correct |
14 |
Correct |
0 ms |
4948 KB |
Output is correct |
15 |
Correct |
0 ms |
4948 KB |
Output is correct |
16 |
Correct |
0 ms |
4948 KB |
Output is correct |
17 |
Correct |
0 ms |
4948 KB |
Output is correct |
18 |
Correct |
0 ms |
4948 KB |
Output is correct |
19 |
Correct |
0 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
4948 KB |
Output is correct |
21 |
Correct |
0 ms |
4948 KB |
Output is correct |
22 |
Correct |
0 ms |
4948 KB |
Output is correct |
23 |
Correct |
0 ms |
4948 KB |
Output is correct |
24 |
Correct |
0 ms |
4948 KB |
Output is correct |
25 |
Correct |
0 ms |
4948 KB |
Output is correct |
26 |
Correct |
3 ms |
4948 KB |
Output is correct |
27 |
Correct |
3 ms |
4948 KB |
Output is correct |
28 |
Correct |
3 ms |
4948 KB |
Output is correct |
29 |
Correct |
3 ms |
4948 KB |
Output is correct |
30 |
Correct |
0 ms |
4948 KB |
Output is correct |
31 |
Correct |
3 ms |
4948 KB |
Output is correct |
32 |
Correct |
0 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
3 ms |
4948 KB |
Output is correct |
35 |
Correct |
3 ms |
4948 KB |
Output is correct |
36 |
Correct |
3 ms |
4948 KB |
Output is correct |
37 |
Correct |
16 ms |
5088 KB |
Output is correct |
38 |
Correct |
19 ms |
5088 KB |
Output is correct |
39 |
Correct |
63 ms |
4948 KB |
Output is correct |
40 |
Correct |
29 ms |
5088 KB |
Output is correct |
41 |
Correct |
63 ms |
4948 KB |
Output is correct |
42 |
Correct |
29 ms |
5088 KB |
Output is correct |
43 |
Correct |
53 ms |
5220 KB |
Output is correct |
44 |
Correct |
49 ms |
5220 KB |
Output is correct |
45 |
Correct |
53 ms |
5220 KB |
Output is correct |
46 |
Correct |
33 ms |
4948 KB |
Output is correct |
47 |
Correct |
26 ms |
5088 KB |
Output is correct |
48 |
Correct |
59 ms |
5220 KB |
Output is correct |
49 |
Correct |
59 ms |
5088 KB |
Output is correct |
50 |
Correct |
29 ms |
5088 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
63 ms |
5220 KB |
Output is correct |
53 |
Correct |
46 ms |
5220 KB |
Output is correct |
54 |
Correct |
66 ms |
5220 KB |
Output is correct |
55 |
Correct |
166 ms |
5416 KB |
Output is correct |
56 |
Correct |
59 ms |
5220 KB |
Output is correct |
57 |
Correct |
139 ms |
5416 KB |
Output is correct |
58 |
Correct |
73 ms |
5220 KB |
Output is correct |
59 |
Correct |
93 ms |
5416 KB |
Output is correct |
60 |
Correct |
19 ms |
4948 KB |
Output is correct |
61 |
Correct |
116 ms |
5416 KB |
Output is correct |
62 |
Correct |
106 ms |
5416 KB |
Output is correct |
63 |
Correct |
136 ms |
5416 KB |
Output is correct |
64 |
Correct |
123 ms |
5416 KB |
Output is correct |
65 |
Correct |
59 ms |
4948 KB |
Output is correct |
66 |
Correct |
59 ms |
5088 KB |
Output is correct |
67 |
Correct |
123 ms |
5416 KB |
Output is correct |
68 |
Correct |
49 ms |
4948 KB |
Output is correct |
69 |
Correct |
413 ms |
5800 KB |
Output is correct |
70 |
Correct |
226 ms |
5416 KB |
Output is correct |
71 |
Correct |
209 ms |
5416 KB |
Output is correct |
72 |
Correct |
203 ms |
4948 KB |
Output is correct |
73 |
Correct |
216 ms |
4948 KB |
Output is correct |
74 |
Correct |
403 ms |
5800 KB |
Output is correct |
75 |
Correct |
329 ms |
5800 KB |
Output is correct |
76 |
Correct |
436 ms |
5800 KB |
Output is correct |
77 |
Correct |
416 ms |
5800 KB |
Output is correct |