#include <bits/stdc++.h>
using namespace std;
long long dp[500*500+1];
long long mod = int(1e9+7);
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]>=mod)dp[j]-=mod;
if(dp[j]<0)dp[j]+=mod;
}
}
if(sum%2||(!dp[sum/2])){
cout<<"0";
return 0;
}
vector<int> v;
for(int i = (arr[0]%2?1:2);i<=sum;i+=2){v.push_back(i);}
for(int it = 0;it<n;it++){
for(int j = arr[it];j<=sum;j++){
dp[j]-=dp[j-arr[it]];
if(dp[j]>=mod)dp[j]-=mod;
if(dp[j]<0)dp[j]+=mod;
}
vector<int> c;
for(auto j:v){
if((sum-arr[it]+j)%2){
continue;
}
int ne = sum-arr[it]+j;
int d = 0;
if(ne/2<=sum)d = (dp[ne/2]>0);
else break;
if(j<=ne/2&&(ne/2)-j<=sum)d|=(dp[(ne/2)-j]>0);
if(d==1)c.push_back(j);
}
v = c;
for(int j = sum;j>=arr[it];j--){
dp[j]+=dp[j-arr[it]];
if(dp[j]>=mod)dp[j]-=mod;
if(dp[j]<0)dp[j]+=mod;
}
}
cout<<v.size()<<"\n";
for(auto i:v)cout<<i<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
9 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
7 ms |
448 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
416 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
9 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
7 ms |
448 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
416 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
364 KB |
Output is correct |
37 |
Correct |
41 ms |
604 KB |
Output is correct |
38 |
Correct |
42 ms |
616 KB |
Output is correct |
39 |
Correct |
46 ms |
980 KB |
Output is correct |
40 |
Correct |
99 ms |
760 KB |
Output is correct |
41 |
Correct |
60 ms |
1264 KB |
Output is correct |
42 |
Correct |
82 ms |
716 KB |
Output is correct |
43 |
Correct |
138 ms |
1132 KB |
Output is correct |
44 |
Correct |
146 ms |
1216 KB |
Output is correct |
45 |
Correct |
153 ms |
1236 KB |
Output is correct |
46 |
Correct |
49 ms |
596 KB |
Output is correct |
47 |
Correct |
91 ms |
748 KB |
Output is correct |
48 |
Correct |
126 ms |
1136 KB |
Output is correct |
49 |
Correct |
87 ms |
1036 KB |
Output is correct |
50 |
Correct |
89 ms |
844 KB |
Output is correct |
51 |
Correct |
21 ms |
468 KB |
Output is correct |
52 |
Correct |
195 ms |
1420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
9 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
7 ms |
448 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
416 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
364 KB |
Output is correct |
37 |
Correct |
41 ms |
604 KB |
Output is correct |
38 |
Correct |
42 ms |
616 KB |
Output is correct |
39 |
Correct |
46 ms |
980 KB |
Output is correct |
40 |
Correct |
99 ms |
760 KB |
Output is correct |
41 |
Correct |
60 ms |
1264 KB |
Output is correct |
42 |
Correct |
82 ms |
716 KB |
Output is correct |
43 |
Correct |
138 ms |
1132 KB |
Output is correct |
44 |
Correct |
146 ms |
1216 KB |
Output is correct |
45 |
Correct |
153 ms |
1236 KB |
Output is correct |
46 |
Correct |
49 ms |
596 KB |
Output is correct |
47 |
Correct |
91 ms |
748 KB |
Output is correct |
48 |
Correct |
126 ms |
1136 KB |
Output is correct |
49 |
Correct |
87 ms |
1036 KB |
Output is correct |
50 |
Correct |
89 ms |
844 KB |
Output is correct |
51 |
Correct |
21 ms |
468 KB |
Output is correct |
52 |
Correct |
195 ms |
1420 KB |
Output is correct |
53 |
Correct |
146 ms |
1116 KB |
Output is correct |
54 |
Correct |
234 ms |
1216 KB |
Output is correct |
55 |
Correct |
422 ms |
2160 KB |
Output is correct |
56 |
Correct |
215 ms |
1232 KB |
Output is correct |
57 |
Correct |
444 ms |
2148 KB |
Output is correct |
58 |
Correct |
244 ms |
1220 KB |
Output is correct |
59 |
Correct |
315 ms |
1692 KB |
Output is correct |
60 |
Correct |
67 ms |
784 KB |
Output is correct |
61 |
Correct |
348 ms |
1568 KB |
Output is correct |
62 |
Correct |
373 ms |
1864 KB |
Output is correct |
63 |
Correct |
368 ms |
1776 KB |
Output is correct |
64 |
Correct |
395 ms |
1896 KB |
Output is correct |
65 |
Correct |
48 ms |
828 KB |
Output is correct |
66 |
Correct |
70 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
9 ms |
468 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
7 ms |
448 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
416 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
4 ms |
452 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
364 KB |
Output is correct |
37 |
Correct |
41 ms |
604 KB |
Output is correct |
38 |
Correct |
42 ms |
616 KB |
Output is correct |
39 |
Correct |
46 ms |
980 KB |
Output is correct |
40 |
Correct |
99 ms |
760 KB |
Output is correct |
41 |
Correct |
60 ms |
1264 KB |
Output is correct |
42 |
Correct |
82 ms |
716 KB |
Output is correct |
43 |
Correct |
138 ms |
1132 KB |
Output is correct |
44 |
Correct |
146 ms |
1216 KB |
Output is correct |
45 |
Correct |
153 ms |
1236 KB |
Output is correct |
46 |
Correct |
49 ms |
596 KB |
Output is correct |
47 |
Correct |
91 ms |
748 KB |
Output is correct |
48 |
Correct |
126 ms |
1136 KB |
Output is correct |
49 |
Correct |
87 ms |
1036 KB |
Output is correct |
50 |
Correct |
89 ms |
844 KB |
Output is correct |
51 |
Correct |
21 ms |
468 KB |
Output is correct |
52 |
Correct |
195 ms |
1420 KB |
Output is correct |
53 |
Correct |
146 ms |
1116 KB |
Output is correct |
54 |
Correct |
234 ms |
1216 KB |
Output is correct |
55 |
Correct |
422 ms |
2160 KB |
Output is correct |
56 |
Correct |
215 ms |
1232 KB |
Output is correct |
57 |
Correct |
444 ms |
2148 KB |
Output is correct |
58 |
Correct |
244 ms |
1220 KB |
Output is correct |
59 |
Correct |
315 ms |
1692 KB |
Output is correct |
60 |
Correct |
67 ms |
784 KB |
Output is correct |
61 |
Correct |
348 ms |
1568 KB |
Output is correct |
62 |
Correct |
373 ms |
1864 KB |
Output is correct |
63 |
Correct |
368 ms |
1776 KB |
Output is correct |
64 |
Correct |
395 ms |
1896 KB |
Output is correct |
65 |
Correct |
48 ms |
828 KB |
Output is correct |
66 |
Correct |
70 ms |
952 KB |
Output is correct |
67 |
Correct |
385 ms |
1648 KB |
Output is correct |
68 |
Correct |
119 ms |
1236 KB |
Output is correct |
69 |
Execution timed out |
1088 ms |
3532 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |