#include <bits/stdc++.h>
using namespace std;
const int MAXN = 502;
int g[MAXN*MAXN];
int ar[MAXN];
int n;
bitset<MAXN * MAXN> kp;
int indd = 0;
int obtainable[MAXN*MAXN];
void knap(int ind){
kp.reset();
kp.set(0);
int s =0; for (int i=0; i<n; i++) if (i!= ind) s+=ar[i];
for (int i=0; i<n; i++){
if (i==ind) continue;
kp |= kp<<ar[i];
}
for (int x=0; x<indd; x++){
int i=obtainable[x];
if (!kp[i]) continue;
if (2*i-s <= 0) continue;
g[2*i-s] ++;
}
}
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.set(0);
for (int i=0; i<n; i++){
kp |= kp << ar[i];
}
for (int i=0; i<MAXN*MAXN; i++){
if (kp[i]) obtainable[indd++] = 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<MAXN*MAXN; i++) if (g[i] == n) good.insert(i);
cout<<good.size()<<'\n';
for (int x: good) cout<<x<<' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
21 |
Correct |
25 ms |
644 KB |
Output is correct |
22 |
Correct |
33 ms |
600 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
54 ms |
648 KB |
Output is correct |
25 |
Correct |
55 ms |
604 KB |
Output is correct |
26 |
Correct |
60 ms |
604 KB |
Output is correct |
27 |
Correct |
60 ms |
604 KB |
Output is correct |
28 |
Correct |
61 ms |
604 KB |
Output is correct |
29 |
Correct |
59 ms |
668 KB |
Output is correct |
30 |
Correct |
59 ms |
604 KB |
Output is correct |
31 |
Correct |
60 ms |
864 KB |
Output is correct |
32 |
Correct |
60 ms |
644 KB |
Output is correct |
33 |
Correct |
60 ms |
604 KB |
Output is correct |
34 |
Correct |
68 ms |
632 KB |
Output is correct |
35 |
Correct |
61 ms |
648 KB |
Output is correct |
36 |
Correct |
59 ms |
628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
21 |
Correct |
25 ms |
644 KB |
Output is correct |
22 |
Correct |
33 ms |
600 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
54 ms |
648 KB |
Output is correct |
25 |
Correct |
55 ms |
604 KB |
Output is correct |
26 |
Correct |
60 ms |
604 KB |
Output is correct |
27 |
Correct |
60 ms |
604 KB |
Output is correct |
28 |
Correct |
61 ms |
604 KB |
Output is correct |
29 |
Correct |
59 ms |
668 KB |
Output is correct |
30 |
Correct |
59 ms |
604 KB |
Output is correct |
31 |
Correct |
60 ms |
864 KB |
Output is correct |
32 |
Correct |
60 ms |
644 KB |
Output is correct |
33 |
Correct |
60 ms |
604 KB |
Output is correct |
34 |
Correct |
68 ms |
632 KB |
Output is correct |
35 |
Correct |
61 ms |
648 KB |
Output is correct |
36 |
Correct |
59 ms |
628 KB |
Output is correct |
37 |
Correct |
236 ms |
1108 KB |
Output is correct |
38 |
Correct |
234 ms |
1264 KB |
Output is correct |
39 |
Correct |
360 ms |
832 KB |
Output is correct |
40 |
Correct |
429 ms |
1864 KB |
Output is correct |
41 |
Correct |
428 ms |
880 KB |
Output is correct |
42 |
Correct |
371 ms |
1616 KB |
Output is correct |
43 |
Correct |
363 ms |
2296 KB |
Output is correct |
44 |
Correct |
385 ms |
2388 KB |
Output is correct |
45 |
Correct |
382 ms |
2308 KB |
Output is correct |
46 |
Correct |
436 ms |
776 KB |
Output is correct |
47 |
Correct |
376 ms |
1620 KB |
Output is correct |
48 |
Correct |
374 ms |
1912 KB |
Output is correct |
49 |
Correct |
408 ms |
944 KB |
Output is correct |
50 |
Correct |
366 ms |
1616 KB |
Output is correct |
51 |
Correct |
373 ms |
860 KB |
Output is correct |
52 |
Correct |
453 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
21 |
Correct |
25 ms |
644 KB |
Output is correct |
22 |
Correct |
33 ms |
600 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
54 ms |
648 KB |
Output is correct |
25 |
Correct |
55 ms |
604 KB |
Output is correct |
26 |
Correct |
60 ms |
604 KB |
Output is correct |
27 |
Correct |
60 ms |
604 KB |
Output is correct |
28 |
Correct |
61 ms |
604 KB |
Output is correct |
29 |
Correct |
59 ms |
668 KB |
Output is correct |
30 |
Correct |
59 ms |
604 KB |
Output is correct |
31 |
Correct |
60 ms |
864 KB |
Output is correct |
32 |
Correct |
60 ms |
644 KB |
Output is correct |
33 |
Correct |
60 ms |
604 KB |
Output is correct |
34 |
Correct |
68 ms |
632 KB |
Output is correct |
35 |
Correct |
61 ms |
648 KB |
Output is correct |
36 |
Correct |
59 ms |
628 KB |
Output is correct |
37 |
Correct |
236 ms |
1108 KB |
Output is correct |
38 |
Correct |
234 ms |
1264 KB |
Output is correct |
39 |
Correct |
360 ms |
832 KB |
Output is correct |
40 |
Correct |
429 ms |
1864 KB |
Output is correct |
41 |
Correct |
428 ms |
880 KB |
Output is correct |
42 |
Correct |
371 ms |
1616 KB |
Output is correct |
43 |
Correct |
363 ms |
2296 KB |
Output is correct |
44 |
Correct |
385 ms |
2388 KB |
Output is correct |
45 |
Correct |
382 ms |
2308 KB |
Output is correct |
46 |
Correct |
436 ms |
776 KB |
Output is correct |
47 |
Correct |
376 ms |
1620 KB |
Output is correct |
48 |
Correct |
374 ms |
1912 KB |
Output is correct |
49 |
Correct |
408 ms |
944 KB |
Output is correct |
50 |
Correct |
366 ms |
1616 KB |
Output is correct |
51 |
Correct |
373 ms |
860 KB |
Output is correct |
52 |
Correct |
453 ms |
2396 KB |
Output is correct |
53 |
Correct |
583 ms |
2128 KB |
Output is correct |
54 |
Correct |
784 ms |
2304 KB |
Output is correct |
55 |
Correct |
753 ms |
3920 KB |
Output is correct |
56 |
Correct |
557 ms |
2308 KB |
Output is correct |
57 |
Correct |
780 ms |
4180 KB |
Output is correct |
58 |
Correct |
772 ms |
2640 KB |
Output is correct |
59 |
Correct |
760 ms |
3156 KB |
Output is correct |
60 |
Correct |
776 ms |
1072 KB |
Output is correct |
61 |
Correct |
733 ms |
3308 KB |
Output is correct |
62 |
Correct |
643 ms |
3664 KB |
Output is correct |
63 |
Correct |
631 ms |
3696 KB |
Output is correct |
64 |
Correct |
617 ms |
3684 KB |
Output is correct |
65 |
Correct |
638 ms |
792 KB |
Output is correct |
66 |
Correct |
558 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
604 KB |
Output is correct |
11 |
Correct |
7 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
604 KB |
Output is correct |
14 |
Correct |
6 ms |
604 KB |
Output is correct |
15 |
Correct |
6 ms |
616 KB |
Output is correct |
16 |
Correct |
7 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
6 ms |
600 KB |
Output is correct |
20 |
Correct |
6 ms |
604 KB |
Output is correct |
21 |
Correct |
25 ms |
644 KB |
Output is correct |
22 |
Correct |
33 ms |
600 KB |
Output is correct |
23 |
Correct |
16 ms |
604 KB |
Output is correct |
24 |
Correct |
54 ms |
648 KB |
Output is correct |
25 |
Correct |
55 ms |
604 KB |
Output is correct |
26 |
Correct |
60 ms |
604 KB |
Output is correct |
27 |
Correct |
60 ms |
604 KB |
Output is correct |
28 |
Correct |
61 ms |
604 KB |
Output is correct |
29 |
Correct |
59 ms |
668 KB |
Output is correct |
30 |
Correct |
59 ms |
604 KB |
Output is correct |
31 |
Correct |
60 ms |
864 KB |
Output is correct |
32 |
Correct |
60 ms |
644 KB |
Output is correct |
33 |
Correct |
60 ms |
604 KB |
Output is correct |
34 |
Correct |
68 ms |
632 KB |
Output is correct |
35 |
Correct |
61 ms |
648 KB |
Output is correct |
36 |
Correct |
59 ms |
628 KB |
Output is correct |
37 |
Correct |
236 ms |
1108 KB |
Output is correct |
38 |
Correct |
234 ms |
1264 KB |
Output is correct |
39 |
Correct |
360 ms |
832 KB |
Output is correct |
40 |
Correct |
429 ms |
1864 KB |
Output is correct |
41 |
Correct |
428 ms |
880 KB |
Output is correct |
42 |
Correct |
371 ms |
1616 KB |
Output is correct |
43 |
Correct |
363 ms |
2296 KB |
Output is correct |
44 |
Correct |
385 ms |
2388 KB |
Output is correct |
45 |
Correct |
382 ms |
2308 KB |
Output is correct |
46 |
Correct |
436 ms |
776 KB |
Output is correct |
47 |
Correct |
376 ms |
1620 KB |
Output is correct |
48 |
Correct |
374 ms |
1912 KB |
Output is correct |
49 |
Correct |
408 ms |
944 KB |
Output is correct |
50 |
Correct |
366 ms |
1616 KB |
Output is correct |
51 |
Correct |
373 ms |
860 KB |
Output is correct |
52 |
Correct |
453 ms |
2396 KB |
Output is correct |
53 |
Correct |
583 ms |
2128 KB |
Output is correct |
54 |
Correct |
784 ms |
2304 KB |
Output is correct |
55 |
Correct |
753 ms |
3920 KB |
Output is correct |
56 |
Correct |
557 ms |
2308 KB |
Output is correct |
57 |
Correct |
780 ms |
4180 KB |
Output is correct |
58 |
Correct |
772 ms |
2640 KB |
Output is correct |
59 |
Correct |
760 ms |
3156 KB |
Output is correct |
60 |
Correct |
776 ms |
1072 KB |
Output is correct |
61 |
Correct |
733 ms |
3308 KB |
Output is correct |
62 |
Correct |
643 ms |
3664 KB |
Output is correct |
63 |
Correct |
631 ms |
3696 KB |
Output is correct |
64 |
Correct |
617 ms |
3684 KB |
Output is correct |
65 |
Correct |
638 ms |
792 KB |
Output is correct |
66 |
Correct |
558 ms |
1104 KB |
Output is correct |
67 |
Correct |
942 ms |
3264 KB |
Output is correct |
68 |
Correct |
4 ms |
604 KB |
Output is correct |
69 |
Execution timed out |
1054 ms |
2140 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |