#include <bits/stdc++.h>
using namespace std;
long long dp[500*500+1];
long long ee[500*500+1];
long long mod = int(1e9+7);
bitset<500*500+1> su;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int arr[n] , sum = 0;
for(int i = 0;i<n;i++){
cin>>arr[i];sum+=arr[i];
}
dp[0] = 1;
for(int i = 0;i<n;i++){
for(int j = sum;j>=arr[i];j--){
dp[j]+=dp[j-arr[i]];
if(dp[j]>=1e18)dp[j]%=mod;
}
}
if(sum%2||(!dp[sum/2])){
cout<<"0";
return 0;
}
for(int i = (arr[0]%2?1:2);i<=sum;i+=2){su[i] = 1;}
for(int it = 0;it<n;it++){
for(int j = 0;j<=sum;j++){
ee[j] = dp[j];
if(j>=arr[it]){
ee[j]-=ee[j-arr[it]];
ee[j]%=mod;
if(ee[j]<0){ee[j]%=mod;ee[j]+=mod;ee[j]%=mod;}
}
}
for(int j = (arr[0]%2?1:2);j<=sum;j+=2){
if((sum-arr[it]+j)%2){
su[j] = 0;
continue;
}
int ne = sum-arr[it]+j;
int d = 0;
if(ne/2<=sum)d = (ee[ne/2]>0);
else break;
if(j<=ne/2&&(ne/2)-j<=sum)d|=(ee[(ne/2)-j]>0);
if(d==0)su[j] = 0;
}
}
cout<<su.count()<<"\n";
for(int i = 1;i<=sum;i++)if(su[i])cout<<i<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
412 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
488 KB |
Output is correct |
27 |
Correct |
8 ms |
476 KB |
Output is correct |
28 |
Correct |
9 ms |
468 KB |
Output is correct |
29 |
Correct |
9 ms |
484 KB |
Output is correct |
30 |
Correct |
6 ms |
424 KB |
Output is correct |
31 |
Correct |
8 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
492 KB |
Output is correct |
34 |
Correct |
8 ms |
492 KB |
Output is correct |
35 |
Correct |
8 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
412 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
488 KB |
Output is correct |
27 |
Correct |
8 ms |
476 KB |
Output is correct |
28 |
Correct |
9 ms |
468 KB |
Output is correct |
29 |
Correct |
9 ms |
484 KB |
Output is correct |
30 |
Correct |
6 ms |
424 KB |
Output is correct |
31 |
Correct |
8 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
492 KB |
Output is correct |
34 |
Correct |
8 ms |
492 KB |
Output is correct |
35 |
Correct |
8 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
47 ms |
636 KB |
Output is correct |
38 |
Correct |
47 ms |
624 KB |
Output is correct |
39 |
Correct |
106 ms |
1292 KB |
Output is correct |
40 |
Correct |
105 ms |
828 KB |
Output is correct |
41 |
Correct |
134 ms |
1464 KB |
Output is correct |
42 |
Correct |
91 ms |
800 KB |
Output is correct |
43 |
Correct |
161 ms |
1252 KB |
Output is correct |
44 |
Correct |
163 ms |
1328 KB |
Output is correct |
45 |
Correct |
171 ms |
1340 KB |
Output is correct |
46 |
Correct |
80 ms |
808 KB |
Output is correct |
47 |
Correct |
104 ms |
840 KB |
Output is correct |
48 |
Correct |
174 ms |
1280 KB |
Output is correct |
49 |
Correct |
144 ms |
1316 KB |
Output is correct |
50 |
Correct |
101 ms |
832 KB |
Output is correct |
51 |
Correct |
20 ms |
572 KB |
Output is correct |
52 |
Correct |
223 ms |
1544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
412 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
488 KB |
Output is correct |
27 |
Correct |
8 ms |
476 KB |
Output is correct |
28 |
Correct |
9 ms |
468 KB |
Output is correct |
29 |
Correct |
9 ms |
484 KB |
Output is correct |
30 |
Correct |
6 ms |
424 KB |
Output is correct |
31 |
Correct |
8 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
492 KB |
Output is correct |
34 |
Correct |
8 ms |
492 KB |
Output is correct |
35 |
Correct |
8 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
47 ms |
636 KB |
Output is correct |
38 |
Correct |
47 ms |
624 KB |
Output is correct |
39 |
Correct |
106 ms |
1292 KB |
Output is correct |
40 |
Correct |
105 ms |
828 KB |
Output is correct |
41 |
Correct |
134 ms |
1464 KB |
Output is correct |
42 |
Correct |
91 ms |
800 KB |
Output is correct |
43 |
Correct |
161 ms |
1252 KB |
Output is correct |
44 |
Correct |
163 ms |
1328 KB |
Output is correct |
45 |
Correct |
171 ms |
1340 KB |
Output is correct |
46 |
Correct |
80 ms |
808 KB |
Output is correct |
47 |
Correct |
104 ms |
840 KB |
Output is correct |
48 |
Correct |
174 ms |
1280 KB |
Output is correct |
49 |
Correct |
144 ms |
1316 KB |
Output is correct |
50 |
Correct |
101 ms |
832 KB |
Output is correct |
51 |
Correct |
20 ms |
572 KB |
Output is correct |
52 |
Correct |
223 ms |
1544 KB |
Output is correct |
53 |
Correct |
170 ms |
1064 KB |
Output is correct |
54 |
Correct |
250 ms |
1316 KB |
Output is correct |
55 |
Correct |
464 ms |
2344 KB |
Output is correct |
56 |
Correct |
217 ms |
1328 KB |
Output is correct |
57 |
Correct |
498 ms |
2412 KB |
Output is correct |
58 |
Correct |
281 ms |
1404 KB |
Output is correct |
59 |
Correct |
333 ms |
1672 KB |
Output is correct |
60 |
Correct |
57 ms |
724 KB |
Output is correct |
61 |
Correct |
368 ms |
1920 KB |
Output is correct |
62 |
Correct |
387 ms |
2080 KB |
Output is correct |
63 |
Correct |
411 ms |
2204 KB |
Output is correct |
64 |
Correct |
390 ms |
2252 KB |
Output is correct |
65 |
Correct |
110 ms |
1072 KB |
Output is correct |
66 |
Correct |
148 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
3 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
412 KB |
Output is correct |
25 |
Correct |
8 ms |
468 KB |
Output is correct |
26 |
Correct |
10 ms |
488 KB |
Output is correct |
27 |
Correct |
8 ms |
476 KB |
Output is correct |
28 |
Correct |
9 ms |
468 KB |
Output is correct |
29 |
Correct |
9 ms |
484 KB |
Output is correct |
30 |
Correct |
6 ms |
424 KB |
Output is correct |
31 |
Correct |
8 ms |
468 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
8 ms |
492 KB |
Output is correct |
34 |
Correct |
8 ms |
492 KB |
Output is correct |
35 |
Correct |
8 ms |
488 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
47 ms |
636 KB |
Output is correct |
38 |
Correct |
47 ms |
624 KB |
Output is correct |
39 |
Correct |
106 ms |
1292 KB |
Output is correct |
40 |
Correct |
105 ms |
828 KB |
Output is correct |
41 |
Correct |
134 ms |
1464 KB |
Output is correct |
42 |
Correct |
91 ms |
800 KB |
Output is correct |
43 |
Correct |
161 ms |
1252 KB |
Output is correct |
44 |
Correct |
163 ms |
1328 KB |
Output is correct |
45 |
Correct |
171 ms |
1340 KB |
Output is correct |
46 |
Correct |
80 ms |
808 KB |
Output is correct |
47 |
Correct |
104 ms |
840 KB |
Output is correct |
48 |
Correct |
174 ms |
1280 KB |
Output is correct |
49 |
Correct |
144 ms |
1316 KB |
Output is correct |
50 |
Correct |
101 ms |
832 KB |
Output is correct |
51 |
Correct |
20 ms |
572 KB |
Output is correct |
52 |
Correct |
223 ms |
1544 KB |
Output is correct |
53 |
Correct |
170 ms |
1064 KB |
Output is correct |
54 |
Correct |
250 ms |
1316 KB |
Output is correct |
55 |
Correct |
464 ms |
2344 KB |
Output is correct |
56 |
Correct |
217 ms |
1328 KB |
Output is correct |
57 |
Correct |
498 ms |
2412 KB |
Output is correct |
58 |
Correct |
281 ms |
1404 KB |
Output is correct |
59 |
Correct |
333 ms |
1672 KB |
Output is correct |
60 |
Correct |
57 ms |
724 KB |
Output is correct |
61 |
Correct |
368 ms |
1920 KB |
Output is correct |
62 |
Correct |
387 ms |
2080 KB |
Output is correct |
63 |
Correct |
411 ms |
2204 KB |
Output is correct |
64 |
Correct |
390 ms |
2252 KB |
Output is correct |
65 |
Correct |
110 ms |
1072 KB |
Output is correct |
66 |
Correct |
148 ms |
1144 KB |
Output is correct |
67 |
Correct |
412 ms |
1704 KB |
Output is correct |
68 |
Correct |
121 ms |
1236 KB |
Output is correct |
69 |
Execution timed out |
1086 ms |
3628 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |