#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
const int mod=998244353,mxn=500+5,lg=30,inf=1e18,minf=-1e18,Mxn=501*501;
int dp[Mxn+10],val[mxn+10],last[Mxn+10];
bool ans[Mxn+10];
int32_t main(){
fastio
int n,sum=0;cin>>n;
for(int i=1;i<=n;i++)cin>>val[i],sum+=val[i];
dp[0]=1;
for(int i=1;i<=n;i++)for(int j=sum;j>=0;j--)if(j-val[i]>=0)dp[j]+=dp[j-val[i]];
if(sum%2||dp[sum/2]==0){
cout<<0;
return 0;
}
for(int i=0;i<=sum;i++)ans[i]=true;
for(int i=1;i<=n;i++){
for(int j=0;j<=sum;j++)last[j]=dp[j];
for(int j=0;j+val[i]<=sum;j++)dp[j+val[i]]-=dp[j];
for(int j=0;j<=sum;j++){
if((sum-val[i]+j)%2==0&&dp[(sum-val[i]+j)/2])ans[j]&=true;
else ans[j]=false;
}
for(int j=0;j<=sum;j++)dp[j]=last[j];
}
int cnt=0;
for(int i=0;i<=sum;i++)if(ans[i])cnt++;
cout<<cnt<<'\n';
for(int i=0;i<=sum;i++)if(ans[i])cout<<i<<" ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2580 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2580 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
7 ms |
2648 KB |
Output is correct |
38 |
Correct |
7 ms |
2652 KB |
Output is correct |
39 |
Correct |
27 ms |
2908 KB |
Output is correct |
40 |
Correct |
16 ms |
2652 KB |
Output is correct |
41 |
Correct |
35 ms |
2904 KB |
Output is correct |
42 |
Correct |
18 ms |
2648 KB |
Output is correct |
43 |
Correct |
24 ms |
2904 KB |
Output is correct |
44 |
Correct |
27 ms |
3248 KB |
Output is correct |
45 |
Correct |
27 ms |
3104 KB |
Output is correct |
46 |
Correct |
14 ms |
2648 KB |
Output is correct |
47 |
Correct |
15 ms |
2652 KB |
Output is correct |
48 |
Correct |
28 ms |
3032 KB |
Output is correct |
49 |
Correct |
27 ms |
2908 KB |
Output is correct |
50 |
Correct |
15 ms |
2648 KB |
Output is correct |
51 |
Correct |
4 ms |
2652 KB |
Output is correct |
52 |
Correct |
34 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2580 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
7 ms |
2648 KB |
Output is correct |
38 |
Correct |
7 ms |
2652 KB |
Output is correct |
39 |
Correct |
27 ms |
2908 KB |
Output is correct |
40 |
Correct |
16 ms |
2652 KB |
Output is correct |
41 |
Correct |
35 ms |
2904 KB |
Output is correct |
42 |
Correct |
18 ms |
2648 KB |
Output is correct |
43 |
Correct |
24 ms |
2904 KB |
Output is correct |
44 |
Correct |
27 ms |
3248 KB |
Output is correct |
45 |
Correct |
27 ms |
3104 KB |
Output is correct |
46 |
Correct |
14 ms |
2648 KB |
Output is correct |
47 |
Correct |
15 ms |
2652 KB |
Output is correct |
48 |
Correct |
28 ms |
3032 KB |
Output is correct |
49 |
Correct |
27 ms |
2908 KB |
Output is correct |
50 |
Correct |
15 ms |
2648 KB |
Output is correct |
51 |
Correct |
4 ms |
2652 KB |
Output is correct |
52 |
Correct |
34 ms |
3156 KB |
Output is correct |
53 |
Correct |
25 ms |
2904 KB |
Output is correct |
54 |
Correct |
34 ms |
2984 KB |
Output is correct |
55 |
Correct |
72 ms |
3716 KB |
Output is correct |
56 |
Correct |
31 ms |
2904 KB |
Output is correct |
57 |
Correct |
72 ms |
3752 KB |
Output is correct |
58 |
Correct |
43 ms |
3152 KB |
Output is correct |
59 |
Correct |
51 ms |
3344 KB |
Output is correct |
60 |
Correct |
8 ms |
2764 KB |
Output is correct |
61 |
Correct |
59 ms |
3412 KB |
Output is correct |
62 |
Correct |
61 ms |
3412 KB |
Output is correct |
63 |
Correct |
65 ms |
3656 KB |
Output is correct |
64 |
Correct |
62 ms |
3412 KB |
Output is correct |
65 |
Correct |
27 ms |
2912 KB |
Output is correct |
66 |
Correct |
31 ms |
2956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
2 ms |
2392 KB |
Output is correct |
26 |
Correct |
3 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
2 ms |
2396 KB |
Output is correct |
29 |
Correct |
3 ms |
2580 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
7 ms |
2648 KB |
Output is correct |
38 |
Correct |
7 ms |
2652 KB |
Output is correct |
39 |
Correct |
27 ms |
2908 KB |
Output is correct |
40 |
Correct |
16 ms |
2652 KB |
Output is correct |
41 |
Correct |
35 ms |
2904 KB |
Output is correct |
42 |
Correct |
18 ms |
2648 KB |
Output is correct |
43 |
Correct |
24 ms |
2904 KB |
Output is correct |
44 |
Correct |
27 ms |
3248 KB |
Output is correct |
45 |
Correct |
27 ms |
3104 KB |
Output is correct |
46 |
Correct |
14 ms |
2648 KB |
Output is correct |
47 |
Correct |
15 ms |
2652 KB |
Output is correct |
48 |
Correct |
28 ms |
3032 KB |
Output is correct |
49 |
Correct |
27 ms |
2908 KB |
Output is correct |
50 |
Correct |
15 ms |
2648 KB |
Output is correct |
51 |
Correct |
4 ms |
2652 KB |
Output is correct |
52 |
Correct |
34 ms |
3156 KB |
Output is correct |
53 |
Correct |
25 ms |
2904 KB |
Output is correct |
54 |
Correct |
34 ms |
2984 KB |
Output is correct |
55 |
Correct |
72 ms |
3716 KB |
Output is correct |
56 |
Correct |
31 ms |
2904 KB |
Output is correct |
57 |
Correct |
72 ms |
3752 KB |
Output is correct |
58 |
Correct |
43 ms |
3152 KB |
Output is correct |
59 |
Correct |
51 ms |
3344 KB |
Output is correct |
60 |
Correct |
8 ms |
2764 KB |
Output is correct |
61 |
Correct |
59 ms |
3412 KB |
Output is correct |
62 |
Correct |
61 ms |
3412 KB |
Output is correct |
63 |
Correct |
65 ms |
3656 KB |
Output is correct |
64 |
Correct |
62 ms |
3412 KB |
Output is correct |
65 |
Correct |
27 ms |
2912 KB |
Output is correct |
66 |
Correct |
31 ms |
2956 KB |
Output is correct |
67 |
Correct |
63 ms |
3188 KB |
Output is correct |
68 |
Correct |
23 ms |
3416 KB |
Output is correct |
69 |
Correct |
202 ms |
4820 KB |
Output is correct |
70 |
Correct |
116 ms |
3924 KB |
Output is correct |
71 |
Correct |
116 ms |
3820 KB |
Output is correct |
72 |
Correct |
105 ms |
3460 KB |
Output is correct |
73 |
Correct |
105 ms |
3416 KB |
Output is correct |
74 |
Correct |
197 ms |
4944 KB |
Output is correct |
75 |
Correct |
156 ms |
4516 KB |
Output is correct |
76 |
Correct |
221 ms |
5076 KB |
Output is correct |
77 |
Correct |
209 ms |
5024 KB |
Output is correct |