#include <bits/stdc++.h>
using namespace std;
const int MAXN = 502;
const int MAXV = MAXN*MAXN;
int g[MAXV];
int ar[MAXN];
int n;
int kp[MAXV];
int tp[MAXV];
void knap(int ind){
for (int i=0; i<MAXV; i++) tp[i] = kp[i];
int s = 0; for (int i=0; i<n; i++) if (i!=ind) s+= ar[i];
for (int i=0; i<MAXV - ar[ind] - 1; i++){
tp[i + ar[ind]] -= tp[i];
}
for (int i=0; i<MAXV; i++){
if (tp[i]){
if (2*i-s<=0) continue;
g[2*i-s] ++;
}
}
}
// new = old + (old<<a[i]);
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
for (int i=0; i<n; i++) cin>>ar[i];
if (n&1) {cout<<0; exit(0);}
int s=0; for (int i=0; i<n; i++) s += ar[i];
kp[0] = 1;
for (int ind=0; ind<n; ind++){
for (int i=MAXV-ar[ind] - 1; i>=0; i--){
kp[i+ar[ind]] += kp[i];
}
}
if (!kp[s/2]) {cout<<0; exit(0);}
for (int i=0; i<n; i++){
knap(i);
}
set<int> good;
for (int i=1; i<MAXV; i++) if (g[i] == n) good.insert(i);
cout<<good.size()<<'\n';
for (int x: good) cout<<x<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2652 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
16 ms |
2508 KB |
Output is correct |
13 |
Correct |
19 ms |
2688 KB |
Output is correct |
14 |
Correct |
21 ms |
2648 KB |
Output is correct |
15 |
Correct |
18 ms |
2688 KB |
Output is correct |
16 |
Correct |
19 ms |
2684 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
15 ms |
2652 KB |
Output is correct |
19 |
Correct |
16 ms |
2692 KB |
Output is correct |
20 |
Correct |
21 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2652 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
16 ms |
2508 KB |
Output is correct |
13 |
Correct |
19 ms |
2688 KB |
Output is correct |
14 |
Correct |
21 ms |
2648 KB |
Output is correct |
15 |
Correct |
18 ms |
2688 KB |
Output is correct |
16 |
Correct |
19 ms |
2684 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
15 ms |
2652 KB |
Output is correct |
19 |
Correct |
16 ms |
2692 KB |
Output is correct |
20 |
Correct |
21 ms |
2688 KB |
Output is correct |
21 |
Correct |
34 ms |
2648 KB |
Output is correct |
22 |
Correct |
38 ms |
2652 KB |
Output is correct |
23 |
Correct |
27 ms |
2648 KB |
Output is correct |
24 |
Correct |
52 ms |
2648 KB |
Output is correct |
25 |
Correct |
48 ms |
2680 KB |
Output is correct |
26 |
Correct |
51 ms |
2676 KB |
Output is correct |
27 |
Correct |
51 ms |
2680 KB |
Output is correct |
28 |
Correct |
58 ms |
2680 KB |
Output is correct |
29 |
Correct |
59 ms |
2896 KB |
Output is correct |
30 |
Correct |
51 ms |
2660 KB |
Output is correct |
31 |
Correct |
51 ms |
2648 KB |
Output is correct |
32 |
Correct |
52 ms |
2648 KB |
Output is correct |
33 |
Correct |
50 ms |
2652 KB |
Output is correct |
34 |
Correct |
50 ms |
2652 KB |
Output is correct |
35 |
Correct |
55 ms |
2648 KB |
Output is correct |
36 |
Correct |
54 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2652 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
16 ms |
2508 KB |
Output is correct |
13 |
Correct |
19 ms |
2688 KB |
Output is correct |
14 |
Correct |
21 ms |
2648 KB |
Output is correct |
15 |
Correct |
18 ms |
2688 KB |
Output is correct |
16 |
Correct |
19 ms |
2684 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
15 ms |
2652 KB |
Output is correct |
19 |
Correct |
16 ms |
2692 KB |
Output is correct |
20 |
Correct |
21 ms |
2688 KB |
Output is correct |
21 |
Correct |
34 ms |
2648 KB |
Output is correct |
22 |
Correct |
38 ms |
2652 KB |
Output is correct |
23 |
Correct |
27 ms |
2648 KB |
Output is correct |
24 |
Correct |
52 ms |
2648 KB |
Output is correct |
25 |
Correct |
48 ms |
2680 KB |
Output is correct |
26 |
Correct |
51 ms |
2676 KB |
Output is correct |
27 |
Correct |
51 ms |
2680 KB |
Output is correct |
28 |
Correct |
58 ms |
2680 KB |
Output is correct |
29 |
Correct |
59 ms |
2896 KB |
Output is correct |
30 |
Correct |
51 ms |
2660 KB |
Output is correct |
31 |
Correct |
51 ms |
2648 KB |
Output is correct |
32 |
Correct |
52 ms |
2648 KB |
Output is correct |
33 |
Correct |
50 ms |
2652 KB |
Output is correct |
34 |
Correct |
50 ms |
2652 KB |
Output is correct |
35 |
Correct |
55 ms |
2648 KB |
Output is correct |
36 |
Correct |
54 ms |
2648 KB |
Output is correct |
37 |
Correct |
99 ms |
2920 KB |
Output is correct |
38 |
Correct |
126 ms |
3156 KB |
Output is correct |
39 |
Correct |
123 ms |
2652 KB |
Output is correct |
40 |
Correct |
135 ms |
3664 KB |
Output is correct |
41 |
Correct |
142 ms |
2644 KB |
Output is correct |
42 |
Correct |
128 ms |
3408 KB |
Output is correct |
43 |
Correct |
126 ms |
3944 KB |
Output is correct |
44 |
Correct |
138 ms |
3924 KB |
Output is correct |
45 |
Correct |
142 ms |
3920 KB |
Output is correct |
46 |
Correct |
153 ms |
2652 KB |
Output is correct |
47 |
Correct |
136 ms |
3440 KB |
Output is correct |
48 |
Correct |
144 ms |
3668 KB |
Output is correct |
49 |
Correct |
125 ms |
2900 KB |
Output is correct |
50 |
Correct |
126 ms |
3408 KB |
Output is correct |
51 |
Correct |
129 ms |
2664 KB |
Output is correct |
52 |
Correct |
148 ms |
4180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2652 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
16 ms |
2508 KB |
Output is correct |
13 |
Correct |
19 ms |
2688 KB |
Output is correct |
14 |
Correct |
21 ms |
2648 KB |
Output is correct |
15 |
Correct |
18 ms |
2688 KB |
Output is correct |
16 |
Correct |
19 ms |
2684 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
15 ms |
2652 KB |
Output is correct |
19 |
Correct |
16 ms |
2692 KB |
Output is correct |
20 |
Correct |
21 ms |
2688 KB |
Output is correct |
21 |
Correct |
34 ms |
2648 KB |
Output is correct |
22 |
Correct |
38 ms |
2652 KB |
Output is correct |
23 |
Correct |
27 ms |
2648 KB |
Output is correct |
24 |
Correct |
52 ms |
2648 KB |
Output is correct |
25 |
Correct |
48 ms |
2680 KB |
Output is correct |
26 |
Correct |
51 ms |
2676 KB |
Output is correct |
27 |
Correct |
51 ms |
2680 KB |
Output is correct |
28 |
Correct |
58 ms |
2680 KB |
Output is correct |
29 |
Correct |
59 ms |
2896 KB |
Output is correct |
30 |
Correct |
51 ms |
2660 KB |
Output is correct |
31 |
Correct |
51 ms |
2648 KB |
Output is correct |
32 |
Correct |
52 ms |
2648 KB |
Output is correct |
33 |
Correct |
50 ms |
2652 KB |
Output is correct |
34 |
Correct |
50 ms |
2652 KB |
Output is correct |
35 |
Correct |
55 ms |
2648 KB |
Output is correct |
36 |
Correct |
54 ms |
2648 KB |
Output is correct |
37 |
Correct |
99 ms |
2920 KB |
Output is correct |
38 |
Correct |
126 ms |
3156 KB |
Output is correct |
39 |
Correct |
123 ms |
2652 KB |
Output is correct |
40 |
Correct |
135 ms |
3664 KB |
Output is correct |
41 |
Correct |
142 ms |
2644 KB |
Output is correct |
42 |
Correct |
128 ms |
3408 KB |
Output is correct |
43 |
Correct |
126 ms |
3944 KB |
Output is correct |
44 |
Correct |
138 ms |
3924 KB |
Output is correct |
45 |
Correct |
142 ms |
3920 KB |
Output is correct |
46 |
Correct |
153 ms |
2652 KB |
Output is correct |
47 |
Correct |
136 ms |
3440 KB |
Output is correct |
48 |
Correct |
144 ms |
3668 KB |
Output is correct |
49 |
Correct |
125 ms |
2900 KB |
Output is correct |
50 |
Correct |
126 ms |
3408 KB |
Output is correct |
51 |
Correct |
129 ms |
2664 KB |
Output is correct |
52 |
Correct |
148 ms |
4180 KB |
Output is correct |
53 |
Correct |
151 ms |
3688 KB |
Output is correct |
54 |
Correct |
194 ms |
3940 KB |
Output is correct |
55 |
Correct |
177 ms |
5408 KB |
Output is correct |
56 |
Correct |
176 ms |
3944 KB |
Output is correct |
57 |
Correct |
180 ms |
5596 KB |
Output is correct |
58 |
Correct |
181 ms |
4180 KB |
Output is correct |
59 |
Correct |
177 ms |
4692 KB |
Output is correct |
60 |
Correct |
174 ms |
2508 KB |
Output is correct |
61 |
Correct |
183 ms |
4796 KB |
Output is correct |
62 |
Correct |
162 ms |
5204 KB |
Output is correct |
63 |
Correct |
165 ms |
5324 KB |
Output is correct |
64 |
Correct |
159 ms |
5116 KB |
Output is correct |
65 |
Correct |
164 ms |
2648 KB |
Output is correct |
66 |
Correct |
158 ms |
2916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2648 KB |
Output is correct |
2 |
Correct |
4 ms |
2652 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
3 ms |
2652 KB |
Output is correct |
5 |
Correct |
9 ms |
2516 KB |
Output is correct |
6 |
Correct |
5 ms |
2904 KB |
Output is correct |
7 |
Correct |
4 ms |
2652 KB |
Output is correct |
8 |
Correct |
7 ms |
2684 KB |
Output is correct |
9 |
Correct |
6 ms |
2648 KB |
Output is correct |
10 |
Correct |
16 ms |
2652 KB |
Output is correct |
11 |
Correct |
18 ms |
2648 KB |
Output is correct |
12 |
Correct |
16 ms |
2508 KB |
Output is correct |
13 |
Correct |
19 ms |
2688 KB |
Output is correct |
14 |
Correct |
21 ms |
2648 KB |
Output is correct |
15 |
Correct |
18 ms |
2688 KB |
Output is correct |
16 |
Correct |
19 ms |
2684 KB |
Output is correct |
17 |
Correct |
12 ms |
2652 KB |
Output is correct |
18 |
Correct |
15 ms |
2652 KB |
Output is correct |
19 |
Correct |
16 ms |
2692 KB |
Output is correct |
20 |
Correct |
21 ms |
2688 KB |
Output is correct |
21 |
Correct |
34 ms |
2648 KB |
Output is correct |
22 |
Correct |
38 ms |
2652 KB |
Output is correct |
23 |
Correct |
27 ms |
2648 KB |
Output is correct |
24 |
Correct |
52 ms |
2648 KB |
Output is correct |
25 |
Correct |
48 ms |
2680 KB |
Output is correct |
26 |
Correct |
51 ms |
2676 KB |
Output is correct |
27 |
Correct |
51 ms |
2680 KB |
Output is correct |
28 |
Correct |
58 ms |
2680 KB |
Output is correct |
29 |
Correct |
59 ms |
2896 KB |
Output is correct |
30 |
Correct |
51 ms |
2660 KB |
Output is correct |
31 |
Correct |
51 ms |
2648 KB |
Output is correct |
32 |
Correct |
52 ms |
2648 KB |
Output is correct |
33 |
Correct |
50 ms |
2652 KB |
Output is correct |
34 |
Correct |
50 ms |
2652 KB |
Output is correct |
35 |
Correct |
55 ms |
2648 KB |
Output is correct |
36 |
Correct |
54 ms |
2648 KB |
Output is correct |
37 |
Correct |
99 ms |
2920 KB |
Output is correct |
38 |
Correct |
126 ms |
3156 KB |
Output is correct |
39 |
Correct |
123 ms |
2652 KB |
Output is correct |
40 |
Correct |
135 ms |
3664 KB |
Output is correct |
41 |
Correct |
142 ms |
2644 KB |
Output is correct |
42 |
Correct |
128 ms |
3408 KB |
Output is correct |
43 |
Correct |
126 ms |
3944 KB |
Output is correct |
44 |
Correct |
138 ms |
3924 KB |
Output is correct |
45 |
Correct |
142 ms |
3920 KB |
Output is correct |
46 |
Correct |
153 ms |
2652 KB |
Output is correct |
47 |
Correct |
136 ms |
3440 KB |
Output is correct |
48 |
Correct |
144 ms |
3668 KB |
Output is correct |
49 |
Correct |
125 ms |
2900 KB |
Output is correct |
50 |
Correct |
126 ms |
3408 KB |
Output is correct |
51 |
Correct |
129 ms |
2664 KB |
Output is correct |
52 |
Correct |
148 ms |
4180 KB |
Output is correct |
53 |
Correct |
151 ms |
3688 KB |
Output is correct |
54 |
Correct |
194 ms |
3940 KB |
Output is correct |
55 |
Correct |
177 ms |
5408 KB |
Output is correct |
56 |
Correct |
176 ms |
3944 KB |
Output is correct |
57 |
Correct |
180 ms |
5596 KB |
Output is correct |
58 |
Correct |
181 ms |
4180 KB |
Output is correct |
59 |
Correct |
177 ms |
4692 KB |
Output is correct |
60 |
Correct |
174 ms |
2508 KB |
Output is correct |
61 |
Correct |
183 ms |
4796 KB |
Output is correct |
62 |
Correct |
162 ms |
5204 KB |
Output is correct |
63 |
Correct |
165 ms |
5324 KB |
Output is correct |
64 |
Correct |
159 ms |
5116 KB |
Output is correct |
65 |
Correct |
164 ms |
2648 KB |
Output is correct |
66 |
Correct |
158 ms |
2916 KB |
Output is correct |
67 |
Correct |
199 ms |
4772 KB |
Output is correct |
68 |
Correct |
55 ms |
2392 KB |
Output is correct |
69 |
Correct |
263 ms |
8356 KB |
Output is correct |
70 |
Correct |
268 ms |
6236 KB |
Output is correct |
71 |
Correct |
250 ms |
6080 KB |
Output is correct |
72 |
Correct |
242 ms |
2900 KB |
Output is correct |
73 |
Correct |
1 ms |
2648 KB |
Output is correct |
74 |
Correct |
256 ms |
9044 KB |
Output is correct |
75 |
Correct |
287 ms |
7508 KB |
Output is correct |
76 |
Correct |
262 ms |
8692 KB |
Output is correct |
77 |
Correct |
261 ms |
9284 KB |
Output is correct |