#include<bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 503;
bitset <250006> ans;
bitset <250006> tek;
bitset <250006> newtek;
int i,j,p,q,n,m,k,sum;
int a[maxn];
void rek(int l,int r,bitset <250006> tek)
{
if(l>r)return ;
if(l==r)
{
///managed to compute the knapsack in tek without this one
tek=(tek<<a[l]);
ans&=tek;
return ;
}
int mid = (l+r)/2;
///l mid; mid+1 r
newtek = tek;
for(i=r;i>=mid+1;i--)
newtek|=(newtek<<(2*a[i]));
rek(l,mid,newtek);
newtek = tek;
for(i=l;i<=mid;i++)
newtek|=(newtek<<(2*a[i]));
rek(mid+1,r,newtek);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a[i];
sum+=a[i];
}
if(sum%2!=0)
{
cout<<0<<endl;
return 0;
}
for(i=2;i<=n;i++)
{
if(a[i]%2!=a[i-1]%2)
{
cout<<0<<endl;
return 0;
}
}
newtek[0]=1;
for(i=1;i<=n;i++)
newtek|=(newtek<<(a[i]));
if(!newtek[sum/2])
{
cout<<0<<endl;
return 0;
}
ans.set();
tek.set(0);
tek[0]=1;
rek(1,n,tek);
int br = 0;
for(i=1;i<sum;i++)
if(ans[i])br++;
cout<<br<<endl;
for(i=sum-1;i>1;i--)
{
if(ans[i])
cout<<sum-i<<" ";
}
return 0;
}
/**
4
1 3 1 5
4
200 200 200 200
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
900 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
904 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
900 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
904 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
1108 KB |
Output is correct |
23 |
Correct |
3 ms |
1020 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
6 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
5 ms |
1152 KB |
Output is correct |
29 |
Correct |
6 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
1108 KB |
Output is correct |
32 |
Correct |
6 ms |
1108 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
6 ms |
1236 KB |
Output is correct |
35 |
Correct |
6 ms |
1108 KB |
Output is correct |
36 |
Correct |
6 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
900 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
904 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
1108 KB |
Output is correct |
23 |
Correct |
3 ms |
1020 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
6 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
5 ms |
1152 KB |
Output is correct |
29 |
Correct |
6 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
1108 KB |
Output is correct |
32 |
Correct |
6 ms |
1108 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
6 ms |
1236 KB |
Output is correct |
35 |
Correct |
6 ms |
1108 KB |
Output is correct |
36 |
Correct |
6 ms |
1108 KB |
Output is correct |
37 |
Correct |
13 ms |
1236 KB |
Output is correct |
38 |
Correct |
13 ms |
1284 KB |
Output is correct |
39 |
Correct |
14 ms |
1148 KB |
Output is correct |
40 |
Correct |
17 ms |
1356 KB |
Output is correct |
41 |
Correct |
15 ms |
1364 KB |
Output is correct |
42 |
Correct |
15 ms |
1236 KB |
Output is correct |
43 |
Correct |
16 ms |
1404 KB |
Output is correct |
44 |
Correct |
19 ms |
1392 KB |
Output is correct |
45 |
Correct |
16 ms |
1396 KB |
Output is correct |
46 |
Correct |
15 ms |
1236 KB |
Output is correct |
47 |
Correct |
16 ms |
1252 KB |
Output is correct |
48 |
Correct |
16 ms |
1268 KB |
Output is correct |
49 |
Correct |
15 ms |
1264 KB |
Output is correct |
50 |
Correct |
16 ms |
1364 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
18 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
900 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
904 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
1108 KB |
Output is correct |
23 |
Correct |
3 ms |
1020 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
6 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
5 ms |
1152 KB |
Output is correct |
29 |
Correct |
6 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
1108 KB |
Output is correct |
32 |
Correct |
6 ms |
1108 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
6 ms |
1236 KB |
Output is correct |
35 |
Correct |
6 ms |
1108 KB |
Output is correct |
36 |
Correct |
6 ms |
1108 KB |
Output is correct |
37 |
Correct |
13 ms |
1236 KB |
Output is correct |
38 |
Correct |
13 ms |
1284 KB |
Output is correct |
39 |
Correct |
14 ms |
1148 KB |
Output is correct |
40 |
Correct |
17 ms |
1356 KB |
Output is correct |
41 |
Correct |
15 ms |
1364 KB |
Output is correct |
42 |
Correct |
15 ms |
1236 KB |
Output is correct |
43 |
Correct |
16 ms |
1404 KB |
Output is correct |
44 |
Correct |
19 ms |
1392 KB |
Output is correct |
45 |
Correct |
16 ms |
1396 KB |
Output is correct |
46 |
Correct |
15 ms |
1236 KB |
Output is correct |
47 |
Correct |
16 ms |
1252 KB |
Output is correct |
48 |
Correct |
16 ms |
1268 KB |
Output is correct |
49 |
Correct |
15 ms |
1264 KB |
Output is correct |
50 |
Correct |
16 ms |
1364 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
18 ms |
1492 KB |
Output is correct |
53 |
Correct |
19 ms |
1492 KB |
Output is correct |
54 |
Correct |
22 ms |
1492 KB |
Output is correct |
55 |
Correct |
24 ms |
1604 KB |
Output is correct |
56 |
Correct |
20 ms |
1472 KB |
Output is correct |
57 |
Correct |
27 ms |
1616 KB |
Output is correct |
58 |
Correct |
23 ms |
1492 KB |
Output is correct |
59 |
Correct |
23 ms |
1476 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
24 ms |
1484 KB |
Output is correct |
62 |
Correct |
22 ms |
1608 KB |
Output is correct |
63 |
Correct |
23 ms |
1536 KB |
Output is correct |
64 |
Correct |
22 ms |
1620 KB |
Output is correct |
65 |
Correct |
19 ms |
1236 KB |
Output is correct |
66 |
Correct |
22 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
852 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
900 KB |
Output is correct |
15 |
Correct |
2 ms |
980 KB |
Output is correct |
16 |
Correct |
2 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
980 KB |
Output is correct |
18 |
Correct |
2 ms |
904 KB |
Output is correct |
19 |
Correct |
2 ms |
980 KB |
Output is correct |
20 |
Correct |
2 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
1108 KB |
Output is correct |
23 |
Correct |
3 ms |
1020 KB |
Output is correct |
24 |
Correct |
5 ms |
1108 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
6 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1108 KB |
Output is correct |
28 |
Correct |
5 ms |
1152 KB |
Output is correct |
29 |
Correct |
6 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
6 ms |
1108 KB |
Output is correct |
32 |
Correct |
6 ms |
1108 KB |
Output is correct |
33 |
Correct |
6 ms |
1108 KB |
Output is correct |
34 |
Correct |
6 ms |
1236 KB |
Output is correct |
35 |
Correct |
6 ms |
1108 KB |
Output is correct |
36 |
Correct |
6 ms |
1108 KB |
Output is correct |
37 |
Correct |
13 ms |
1236 KB |
Output is correct |
38 |
Correct |
13 ms |
1284 KB |
Output is correct |
39 |
Correct |
14 ms |
1148 KB |
Output is correct |
40 |
Correct |
17 ms |
1356 KB |
Output is correct |
41 |
Correct |
15 ms |
1364 KB |
Output is correct |
42 |
Correct |
15 ms |
1236 KB |
Output is correct |
43 |
Correct |
16 ms |
1404 KB |
Output is correct |
44 |
Correct |
19 ms |
1392 KB |
Output is correct |
45 |
Correct |
16 ms |
1396 KB |
Output is correct |
46 |
Correct |
15 ms |
1236 KB |
Output is correct |
47 |
Correct |
16 ms |
1252 KB |
Output is correct |
48 |
Correct |
16 ms |
1268 KB |
Output is correct |
49 |
Correct |
15 ms |
1264 KB |
Output is correct |
50 |
Correct |
16 ms |
1364 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
18 ms |
1492 KB |
Output is correct |
53 |
Correct |
19 ms |
1492 KB |
Output is correct |
54 |
Correct |
22 ms |
1492 KB |
Output is correct |
55 |
Correct |
24 ms |
1604 KB |
Output is correct |
56 |
Correct |
20 ms |
1472 KB |
Output is correct |
57 |
Correct |
27 ms |
1616 KB |
Output is correct |
58 |
Correct |
23 ms |
1492 KB |
Output is correct |
59 |
Correct |
23 ms |
1476 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
24 ms |
1484 KB |
Output is correct |
62 |
Correct |
22 ms |
1608 KB |
Output is correct |
63 |
Correct |
23 ms |
1536 KB |
Output is correct |
64 |
Correct |
22 ms |
1620 KB |
Output is correct |
65 |
Correct |
19 ms |
1236 KB |
Output is correct |
66 |
Correct |
22 ms |
1352 KB |
Output is correct |
67 |
Correct |
29 ms |
1492 KB |
Output is correct |
68 |
Correct |
3 ms |
340 KB |
Output is correct |
69 |
Correct |
37 ms |
1924 KB |
Output is correct |
70 |
Correct |
34 ms |
1748 KB |
Output is correct |
71 |
Correct |
36 ms |
1740 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
340 KB |
Output is correct |
74 |
Correct |
45 ms |
2016 KB |
Output is correct |
75 |
Correct |
42 ms |
1868 KB |
Output is correct |
76 |
Correct |
44 ms |
1988 KB |
Output is correct |
77 |
Correct |
39 ms |
1952 KB |
Output is correct |