#pragma GCC optimize("O3,unroll-loops")
#include<iostream>
#include<bitset>
using namespace std;
int n,tot;
int a[505];
bitset<150005> dp;
int variante[250005],cntv;
int newv[250005],cntnew;
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]%2!=a[1]%2)
{
cout<<0;
return 0;
}
tot+=a[i];
}
if(tot%2==1)
{
cout<<0;
return 0;
}
for(int i=1;i<=tot;i++)
if(i%2==a[1]%2)
variante[++cntv]=i;
for(int i=0;i<=n;i++)
{
dp.reset();
dp[0]=1;
for(int j=1;j<=n;j++)
{
if(i!=j)
dp |= (dp<<a[j]);
}
if(i==0)
{
if(dp[tot/2]==0)
{
cout<<0;
return 0;
}
continue;
}
cntnew=0;
for(int j=1;j<=cntv;j++)
{
int x = variante[j];
if((tot-a[i]+x)%2==0 && dp[(tot-a[i]+x)/2])
newv[++cntnew] = x;
///tot - a[i] + x
}
cntv=cntnew;
for(int j=1;j<=cntnew;j++)
variante[j] = newv[j];
}
cout<<cntv<<"\n";
for(int i=1;i<=cntv;i++)
cout<<variante[i]<<" ";
return 0;
}
/**
3
2 2 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
10 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
20 ms |
348 KB |
Output is correct |
25 |
Correct |
20 ms |
348 KB |
Output is correct |
26 |
Correct |
25 ms |
348 KB |
Output is correct |
27 |
Correct |
23 ms |
348 KB |
Output is correct |
28 |
Correct |
23 ms |
348 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
23 ms |
552 KB |
Output is correct |
32 |
Correct |
23 ms |
536 KB |
Output is correct |
33 |
Correct |
23 ms |
348 KB |
Output is correct |
34 |
Correct |
24 ms |
516 KB |
Output is correct |
35 |
Correct |
28 ms |
348 KB |
Output is correct |
36 |
Correct |
23 ms |
528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
10 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
20 ms |
348 KB |
Output is correct |
25 |
Correct |
20 ms |
348 KB |
Output is correct |
26 |
Correct |
25 ms |
348 KB |
Output is correct |
27 |
Correct |
23 ms |
348 KB |
Output is correct |
28 |
Correct |
23 ms |
348 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
23 ms |
552 KB |
Output is correct |
32 |
Correct |
23 ms |
536 KB |
Output is correct |
33 |
Correct |
23 ms |
348 KB |
Output is correct |
34 |
Correct |
24 ms |
516 KB |
Output is correct |
35 |
Correct |
28 ms |
348 KB |
Output is correct |
36 |
Correct |
23 ms |
528 KB |
Output is correct |
37 |
Correct |
93 ms |
596 KB |
Output is correct |
38 |
Correct |
91 ms |
596 KB |
Output is correct |
39 |
Correct |
138 ms |
600 KB |
Output is correct |
40 |
Correct |
189 ms |
636 KB |
Output is correct |
41 |
Correct |
172 ms |
644 KB |
Output is correct |
42 |
Correct |
145 ms |
608 KB |
Output is correct |
43 |
Correct |
150 ms |
712 KB |
Output is correct |
44 |
Correct |
147 ms |
708 KB |
Output is correct |
45 |
Correct |
148 ms |
848 KB |
Output is correct |
46 |
Correct |
162 ms |
604 KB |
Output is correct |
47 |
Correct |
145 ms |
640 KB |
Output is correct |
48 |
Correct |
153 ms |
604 KB |
Output is correct |
49 |
Correct |
138 ms |
688 KB |
Output is correct |
50 |
Correct |
149 ms |
628 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
178 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
10 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
20 ms |
348 KB |
Output is correct |
25 |
Correct |
20 ms |
348 KB |
Output is correct |
26 |
Correct |
25 ms |
348 KB |
Output is correct |
27 |
Correct |
23 ms |
348 KB |
Output is correct |
28 |
Correct |
23 ms |
348 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
23 ms |
552 KB |
Output is correct |
32 |
Correct |
23 ms |
536 KB |
Output is correct |
33 |
Correct |
23 ms |
348 KB |
Output is correct |
34 |
Correct |
24 ms |
516 KB |
Output is correct |
35 |
Correct |
28 ms |
348 KB |
Output is correct |
36 |
Correct |
23 ms |
528 KB |
Output is correct |
37 |
Correct |
93 ms |
596 KB |
Output is correct |
38 |
Correct |
91 ms |
596 KB |
Output is correct |
39 |
Correct |
138 ms |
600 KB |
Output is correct |
40 |
Correct |
189 ms |
636 KB |
Output is correct |
41 |
Correct |
172 ms |
644 KB |
Output is correct |
42 |
Correct |
145 ms |
608 KB |
Output is correct |
43 |
Correct |
150 ms |
712 KB |
Output is correct |
44 |
Correct |
147 ms |
708 KB |
Output is correct |
45 |
Correct |
148 ms |
848 KB |
Output is correct |
46 |
Correct |
162 ms |
604 KB |
Output is correct |
47 |
Correct |
145 ms |
640 KB |
Output is correct |
48 |
Correct |
153 ms |
604 KB |
Output is correct |
49 |
Correct |
138 ms |
688 KB |
Output is correct |
50 |
Correct |
149 ms |
628 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
178 ms |
772 KB |
Output is correct |
53 |
Correct |
213 ms |
604 KB |
Output is correct |
54 |
Correct |
292 ms |
848 KB |
Output is correct |
55 |
Correct |
299 ms |
1168 KB |
Output is correct |
56 |
Correct |
229 ms |
716 KB |
Output is correct |
57 |
Correct |
291 ms |
1192 KB |
Output is correct |
58 |
Correct |
299 ms |
848 KB |
Output is correct |
59 |
Correct |
283 ms |
856 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
311 ms |
828 KB |
Output is correct |
62 |
Correct |
249 ms |
1124 KB |
Output is correct |
63 |
Correct |
246 ms |
1168 KB |
Output is correct |
64 |
Correct |
241 ms |
1160 KB |
Output is correct |
65 |
Correct |
215 ms |
604 KB |
Output is correct |
66 |
Correct |
220 ms |
804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
10 ms |
348 KB |
Output is correct |
22 |
Correct |
13 ms |
348 KB |
Output is correct |
23 |
Correct |
6 ms |
348 KB |
Output is correct |
24 |
Correct |
20 ms |
348 KB |
Output is correct |
25 |
Correct |
20 ms |
348 KB |
Output is correct |
26 |
Correct |
25 ms |
348 KB |
Output is correct |
27 |
Correct |
23 ms |
348 KB |
Output is correct |
28 |
Correct |
23 ms |
348 KB |
Output is correct |
29 |
Correct |
22 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
23 ms |
552 KB |
Output is correct |
32 |
Correct |
23 ms |
536 KB |
Output is correct |
33 |
Correct |
23 ms |
348 KB |
Output is correct |
34 |
Correct |
24 ms |
516 KB |
Output is correct |
35 |
Correct |
28 ms |
348 KB |
Output is correct |
36 |
Correct |
23 ms |
528 KB |
Output is correct |
37 |
Correct |
93 ms |
596 KB |
Output is correct |
38 |
Correct |
91 ms |
596 KB |
Output is correct |
39 |
Correct |
138 ms |
600 KB |
Output is correct |
40 |
Correct |
189 ms |
636 KB |
Output is correct |
41 |
Correct |
172 ms |
644 KB |
Output is correct |
42 |
Correct |
145 ms |
608 KB |
Output is correct |
43 |
Correct |
150 ms |
712 KB |
Output is correct |
44 |
Correct |
147 ms |
708 KB |
Output is correct |
45 |
Correct |
148 ms |
848 KB |
Output is correct |
46 |
Correct |
162 ms |
604 KB |
Output is correct |
47 |
Correct |
145 ms |
640 KB |
Output is correct |
48 |
Correct |
153 ms |
604 KB |
Output is correct |
49 |
Correct |
138 ms |
688 KB |
Output is correct |
50 |
Correct |
149 ms |
628 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
178 ms |
772 KB |
Output is correct |
53 |
Correct |
213 ms |
604 KB |
Output is correct |
54 |
Correct |
292 ms |
848 KB |
Output is correct |
55 |
Correct |
299 ms |
1168 KB |
Output is correct |
56 |
Correct |
229 ms |
716 KB |
Output is correct |
57 |
Correct |
291 ms |
1192 KB |
Output is correct |
58 |
Correct |
299 ms |
848 KB |
Output is correct |
59 |
Correct |
283 ms |
856 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
311 ms |
828 KB |
Output is correct |
62 |
Correct |
249 ms |
1124 KB |
Output is correct |
63 |
Correct |
246 ms |
1168 KB |
Output is correct |
64 |
Correct |
241 ms |
1160 KB |
Output is correct |
65 |
Correct |
215 ms |
604 KB |
Output is correct |
66 |
Correct |
220 ms |
804 KB |
Output is correct |
67 |
Correct |
398 ms |
812 KB |
Output is correct |
68 |
Correct |
2 ms |
600 KB |
Output is correct |
69 |
Incorrect |
579 ms |
1364 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |