#include <bits/stdc++.h>
using namespace std;
long long dp[2*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;
long long 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 = 2*sum;j>=arr[i];j--){
dp[j]+=dp[j-arr[i]];
dp[j]%=mod;
}
}
if(sum%2||(!dp[sum/2])){
cout<<"0";
return 0;
}
int su[sum+1];
for(int i = 1;i<=sum;i++)su[i] = 1;
for(int it = 0;it<n;it++){
for(int j = arr[it];j<=2*sum;j++){
dp[j]-=dp[j-arr[it]];
dp[j]%=mod;dp[j]+=mod;dp[j]%=mod;
}
for(int j = 1;j<=sum;j++){
if((sum-arr[it]+j)%2){
su[j]=0;
}
int ne = sum-arr[it]+j;
int d = (dp[ne/2]>0);
if(j<=ne/2)d|=(dp[(ne/2)-j]>0);
su[j]&=d;
}
for(int j = 2*sum;j>=arr[it];j--){
dp[j]+=dp[j-arr[it]];
dp[j]%=mod;
}
}
vector<int> v;
for(int i = 1;i<=sum;i++){
if(su[i])v.push_back(i);
}
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 |
1 ms |
340 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 |
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 |
1 ms |
340 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 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 |
1 ms |
340 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
10 ms |
388 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
18 ms |
404 KB |
Output is correct |
25 |
Correct |
35 ms |
476 KB |
Output is correct |
26 |
Correct |
39 ms |
476 KB |
Output is correct |
27 |
Correct |
39 ms |
488 KB |
Output is correct |
28 |
Correct |
38 ms |
468 KB |
Output is correct |
29 |
Correct |
38 ms |
496 KB |
Output is correct |
30 |
Correct |
21 ms |
428 KB |
Output is correct |
31 |
Correct |
30 ms |
464 KB |
Output is correct |
32 |
Correct |
19 ms |
340 KB |
Output is correct |
33 |
Correct |
40 ms |
468 KB |
Output is correct |
34 |
Correct |
41 ms |
596 KB |
Output is correct |
35 |
Correct |
44 ms |
480 KB |
Output is correct |
36 |
Correct |
19 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 |
1 ms |
340 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
10 ms |
388 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
18 ms |
404 KB |
Output is correct |
25 |
Correct |
35 ms |
476 KB |
Output is correct |
26 |
Correct |
39 ms |
476 KB |
Output is correct |
27 |
Correct |
39 ms |
488 KB |
Output is correct |
28 |
Correct |
38 ms |
468 KB |
Output is correct |
29 |
Correct |
38 ms |
496 KB |
Output is correct |
30 |
Correct |
21 ms |
428 KB |
Output is correct |
31 |
Correct |
30 ms |
464 KB |
Output is correct |
32 |
Correct |
19 ms |
340 KB |
Output is correct |
33 |
Correct |
40 ms |
468 KB |
Output is correct |
34 |
Correct |
41 ms |
596 KB |
Output is correct |
35 |
Correct |
44 ms |
480 KB |
Output is correct |
36 |
Correct |
19 ms |
340 KB |
Output is correct |
37 |
Correct |
152 ms |
752 KB |
Output is correct |
38 |
Correct |
153 ms |
828 KB |
Output is correct |
39 |
Correct |
608 ms |
1528 KB |
Output is correct |
40 |
Correct |
339 ms |
1148 KB |
Output is correct |
41 |
Correct |
767 ms |
1728 KB |
Output is correct |
42 |
Correct |
291 ms |
1100 KB |
Output is correct |
43 |
Correct |
527 ms |
1688 KB |
Output is correct |
44 |
Correct |
548 ms |
1696 KB |
Output is correct |
45 |
Correct |
549 ms |
1836 KB |
Output is correct |
46 |
Correct |
335 ms |
804 KB |
Output is correct |
47 |
Correct |
321 ms |
1076 KB |
Output is correct |
48 |
Correct |
602 ms |
1756 KB |
Output is correct |
49 |
Correct |
600 ms |
1512 KB |
Output is correct |
50 |
Correct |
328 ms |
1152 KB |
Output is correct |
51 |
Correct |
71 ms |
800 KB |
Output is correct |
52 |
Correct |
741 ms |
2040 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 |
1 ms |
340 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
10 ms |
388 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
18 ms |
404 KB |
Output is correct |
25 |
Correct |
35 ms |
476 KB |
Output is correct |
26 |
Correct |
39 ms |
476 KB |
Output is correct |
27 |
Correct |
39 ms |
488 KB |
Output is correct |
28 |
Correct |
38 ms |
468 KB |
Output is correct |
29 |
Correct |
38 ms |
496 KB |
Output is correct |
30 |
Correct |
21 ms |
428 KB |
Output is correct |
31 |
Correct |
30 ms |
464 KB |
Output is correct |
32 |
Correct |
19 ms |
340 KB |
Output is correct |
33 |
Correct |
40 ms |
468 KB |
Output is correct |
34 |
Correct |
41 ms |
596 KB |
Output is correct |
35 |
Correct |
44 ms |
480 KB |
Output is correct |
36 |
Correct |
19 ms |
340 KB |
Output is correct |
37 |
Correct |
152 ms |
752 KB |
Output is correct |
38 |
Correct |
153 ms |
828 KB |
Output is correct |
39 |
Correct |
608 ms |
1528 KB |
Output is correct |
40 |
Correct |
339 ms |
1148 KB |
Output is correct |
41 |
Correct |
767 ms |
1728 KB |
Output is correct |
42 |
Correct |
291 ms |
1100 KB |
Output is correct |
43 |
Correct |
527 ms |
1688 KB |
Output is correct |
44 |
Correct |
548 ms |
1696 KB |
Output is correct |
45 |
Correct |
549 ms |
1836 KB |
Output is correct |
46 |
Correct |
335 ms |
804 KB |
Output is correct |
47 |
Correct |
321 ms |
1076 KB |
Output is correct |
48 |
Correct |
602 ms |
1756 KB |
Output is correct |
49 |
Correct |
600 ms |
1512 KB |
Output is correct |
50 |
Correct |
328 ms |
1152 KB |
Output is correct |
51 |
Correct |
71 ms |
800 KB |
Output is correct |
52 |
Correct |
741 ms |
2040 KB |
Output is correct |
53 |
Correct |
531 ms |
1540 KB |
Output is correct |
54 |
Correct |
761 ms |
1780 KB |
Output is correct |
55 |
Execution timed out |
1085 ms |
2428 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
340 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 |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
8 ms |
384 KB |
Output is correct |
22 |
Correct |
10 ms |
388 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
18 ms |
404 KB |
Output is correct |
25 |
Correct |
35 ms |
476 KB |
Output is correct |
26 |
Correct |
39 ms |
476 KB |
Output is correct |
27 |
Correct |
39 ms |
488 KB |
Output is correct |
28 |
Correct |
38 ms |
468 KB |
Output is correct |
29 |
Correct |
38 ms |
496 KB |
Output is correct |
30 |
Correct |
21 ms |
428 KB |
Output is correct |
31 |
Correct |
30 ms |
464 KB |
Output is correct |
32 |
Correct |
19 ms |
340 KB |
Output is correct |
33 |
Correct |
40 ms |
468 KB |
Output is correct |
34 |
Correct |
41 ms |
596 KB |
Output is correct |
35 |
Correct |
44 ms |
480 KB |
Output is correct |
36 |
Correct |
19 ms |
340 KB |
Output is correct |
37 |
Correct |
152 ms |
752 KB |
Output is correct |
38 |
Correct |
153 ms |
828 KB |
Output is correct |
39 |
Correct |
608 ms |
1528 KB |
Output is correct |
40 |
Correct |
339 ms |
1148 KB |
Output is correct |
41 |
Correct |
767 ms |
1728 KB |
Output is correct |
42 |
Correct |
291 ms |
1100 KB |
Output is correct |
43 |
Correct |
527 ms |
1688 KB |
Output is correct |
44 |
Correct |
548 ms |
1696 KB |
Output is correct |
45 |
Correct |
549 ms |
1836 KB |
Output is correct |
46 |
Correct |
335 ms |
804 KB |
Output is correct |
47 |
Correct |
321 ms |
1076 KB |
Output is correct |
48 |
Correct |
602 ms |
1756 KB |
Output is correct |
49 |
Correct |
600 ms |
1512 KB |
Output is correct |
50 |
Correct |
328 ms |
1152 KB |
Output is correct |
51 |
Correct |
71 ms |
800 KB |
Output is correct |
52 |
Correct |
741 ms |
2040 KB |
Output is correct |
53 |
Correct |
531 ms |
1540 KB |
Output is correct |
54 |
Correct |
761 ms |
1780 KB |
Output is correct |
55 |
Execution timed out |
1085 ms |
2428 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |