#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define left (h<<1),l,(l + r)/2
#define right ((h<<1)|1),(l + r)/2 + 1,r
#define pii pair<int,int>
#define ll long long
using namespace std;
const int N = 500 + 5;
int a[N],n,sum;
bitset <250005> dp,ans;
void go(int l,int r){
if (l == r){
for (int x = 0; x <= 250000; x++){
int newsum = sum - a[l] + x;
if (!(newsum%2==0 && newsum/2 >= x && dp[newsum/2 - x]))
ans[x] = 0;
}
return;
}
int mid = (l + r)>>1;
//right child-shi gadavdivart
bitset <250005> olddp = dp;
for (int j = l; j <= mid; j++){
dp |= (dp << a[j]);
}
go(mid + 1,r);
//left child-shi gadavdivart
dp = olddp;
for (int j = mid + 1; j <= r; j++){
dp |= (dp << a[j]);
}
go(l,mid);
dp = olddp;
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
cin>>n;
dp[0] = 1;
for (int i = 1; i <= n; i++){
cin >> a[i];
sum += a[i];
dp |= (dp << a[i]);
}
if (sum & 1 || !dp[sum/2]){
cout<<0;
exit(0);
}
for (int j = 0; j <= 250000; j++)
ans[j] = 1;
dp = 0;
dp[0] = 1;
go(1,n);
vector <int> res;
for (int j = 0; j <= 250000; j++)
if (ans[j]) res.pb(j);
cout<<(int)res.size()<<endl;
for (int x: res)
cout<<x<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
11 |
Correct |
17 ms |
1112 KB |
Output is correct |
12 |
Correct |
17 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1116 KB |
Output is correct |
14 |
Correct |
16 ms |
1128 KB |
Output is correct |
15 |
Correct |
15 ms |
1376 KB |
Output is correct |
16 |
Correct |
16 ms |
1124 KB |
Output is correct |
17 |
Correct |
12 ms |
1040 KB |
Output is correct |
18 |
Correct |
15 ms |
1132 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
17 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
11 |
Correct |
17 ms |
1112 KB |
Output is correct |
12 |
Correct |
17 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1116 KB |
Output is correct |
14 |
Correct |
16 ms |
1128 KB |
Output is correct |
15 |
Correct |
15 ms |
1376 KB |
Output is correct |
16 |
Correct |
16 ms |
1124 KB |
Output is correct |
17 |
Correct |
12 ms |
1040 KB |
Output is correct |
18 |
Correct |
15 ms |
1132 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
17 ms |
1116 KB |
Output is correct |
21 |
Correct |
34 ms |
1116 KB |
Output is correct |
22 |
Correct |
39 ms |
1300 KB |
Output is correct |
23 |
Correct |
27 ms |
1112 KB |
Output is correct |
24 |
Correct |
53 ms |
1300 KB |
Output is correct |
25 |
Correct |
50 ms |
1312 KB |
Output is correct |
26 |
Correct |
52 ms |
1112 KB |
Output is correct |
27 |
Correct |
53 ms |
1116 KB |
Output is correct |
28 |
Correct |
52 ms |
1112 KB |
Output is correct |
29 |
Correct |
52 ms |
1284 KB |
Output is correct |
30 |
Correct |
52 ms |
1112 KB |
Output is correct |
31 |
Correct |
52 ms |
1112 KB |
Output is correct |
32 |
Correct |
52 ms |
1116 KB |
Output is correct |
33 |
Correct |
52 ms |
1112 KB |
Output is correct |
34 |
Correct |
53 ms |
1112 KB |
Output is correct |
35 |
Correct |
52 ms |
1112 KB |
Output is correct |
36 |
Correct |
52 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
11 |
Correct |
17 ms |
1112 KB |
Output is correct |
12 |
Correct |
17 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1116 KB |
Output is correct |
14 |
Correct |
16 ms |
1128 KB |
Output is correct |
15 |
Correct |
15 ms |
1376 KB |
Output is correct |
16 |
Correct |
16 ms |
1124 KB |
Output is correct |
17 |
Correct |
12 ms |
1040 KB |
Output is correct |
18 |
Correct |
15 ms |
1132 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
17 ms |
1116 KB |
Output is correct |
21 |
Correct |
34 ms |
1116 KB |
Output is correct |
22 |
Correct |
39 ms |
1300 KB |
Output is correct |
23 |
Correct |
27 ms |
1112 KB |
Output is correct |
24 |
Correct |
53 ms |
1300 KB |
Output is correct |
25 |
Correct |
50 ms |
1312 KB |
Output is correct |
26 |
Correct |
52 ms |
1112 KB |
Output is correct |
27 |
Correct |
53 ms |
1116 KB |
Output is correct |
28 |
Correct |
52 ms |
1112 KB |
Output is correct |
29 |
Correct |
52 ms |
1284 KB |
Output is correct |
30 |
Correct |
52 ms |
1112 KB |
Output is correct |
31 |
Correct |
52 ms |
1112 KB |
Output is correct |
32 |
Correct |
52 ms |
1116 KB |
Output is correct |
33 |
Correct |
52 ms |
1112 KB |
Output is correct |
34 |
Correct |
53 ms |
1112 KB |
Output is correct |
35 |
Correct |
52 ms |
1112 KB |
Output is correct |
36 |
Correct |
52 ms |
1112 KB |
Output is correct |
37 |
Correct |
101 ms |
1380 KB |
Output is correct |
38 |
Correct |
103 ms |
1376 KB |
Output is correct |
39 |
Correct |
133 ms |
1616 KB |
Output is correct |
40 |
Correct |
135 ms |
1620 KB |
Output is correct |
41 |
Correct |
152 ms |
1372 KB |
Output is correct |
42 |
Correct |
127 ms |
1384 KB |
Output is correct |
43 |
Correct |
119 ms |
1616 KB |
Output is correct |
44 |
Correct |
119 ms |
1616 KB |
Output is correct |
45 |
Correct |
124 ms |
1652 KB |
Output is correct |
46 |
Correct |
146 ms |
1620 KB |
Output is correct |
47 |
Correct |
124 ms |
1508 KB |
Output is correct |
48 |
Correct |
123 ms |
1616 KB |
Output is correct |
49 |
Correct |
131 ms |
1368 KB |
Output is correct |
50 |
Correct |
124 ms |
1380 KB |
Output is correct |
51 |
Correct |
2 ms |
348 KB |
Output is correct |
52 |
Correct |
130 ms |
1732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
11 |
Correct |
17 ms |
1112 KB |
Output is correct |
12 |
Correct |
17 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1116 KB |
Output is correct |
14 |
Correct |
16 ms |
1128 KB |
Output is correct |
15 |
Correct |
15 ms |
1376 KB |
Output is correct |
16 |
Correct |
16 ms |
1124 KB |
Output is correct |
17 |
Correct |
12 ms |
1040 KB |
Output is correct |
18 |
Correct |
15 ms |
1132 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
17 ms |
1116 KB |
Output is correct |
21 |
Correct |
34 ms |
1116 KB |
Output is correct |
22 |
Correct |
39 ms |
1300 KB |
Output is correct |
23 |
Correct |
27 ms |
1112 KB |
Output is correct |
24 |
Correct |
53 ms |
1300 KB |
Output is correct |
25 |
Correct |
50 ms |
1312 KB |
Output is correct |
26 |
Correct |
52 ms |
1112 KB |
Output is correct |
27 |
Correct |
53 ms |
1116 KB |
Output is correct |
28 |
Correct |
52 ms |
1112 KB |
Output is correct |
29 |
Correct |
52 ms |
1284 KB |
Output is correct |
30 |
Correct |
52 ms |
1112 KB |
Output is correct |
31 |
Correct |
52 ms |
1112 KB |
Output is correct |
32 |
Correct |
52 ms |
1116 KB |
Output is correct |
33 |
Correct |
52 ms |
1112 KB |
Output is correct |
34 |
Correct |
53 ms |
1112 KB |
Output is correct |
35 |
Correct |
52 ms |
1112 KB |
Output is correct |
36 |
Correct |
52 ms |
1112 KB |
Output is correct |
37 |
Correct |
101 ms |
1380 KB |
Output is correct |
38 |
Correct |
103 ms |
1376 KB |
Output is correct |
39 |
Correct |
133 ms |
1616 KB |
Output is correct |
40 |
Correct |
135 ms |
1620 KB |
Output is correct |
41 |
Correct |
152 ms |
1372 KB |
Output is correct |
42 |
Correct |
127 ms |
1384 KB |
Output is correct |
43 |
Correct |
119 ms |
1616 KB |
Output is correct |
44 |
Correct |
119 ms |
1616 KB |
Output is correct |
45 |
Correct |
124 ms |
1652 KB |
Output is correct |
46 |
Correct |
146 ms |
1620 KB |
Output is correct |
47 |
Correct |
124 ms |
1508 KB |
Output is correct |
48 |
Correct |
123 ms |
1616 KB |
Output is correct |
49 |
Correct |
131 ms |
1368 KB |
Output is correct |
50 |
Correct |
124 ms |
1380 KB |
Output is correct |
51 |
Correct |
2 ms |
348 KB |
Output is correct |
52 |
Correct |
130 ms |
1732 KB |
Output is correct |
53 |
Correct |
146 ms |
1748 KB |
Output is correct |
54 |
Correct |
176 ms |
1744 KB |
Output is correct |
55 |
Correct |
159 ms |
1876 KB |
Output is correct |
56 |
Correct |
148 ms |
1744 KB |
Output is correct |
57 |
Correct |
155 ms |
2128 KB |
Output is correct |
58 |
Correct |
168 ms |
1724 KB |
Output is correct |
59 |
Correct |
164 ms |
1748 KB |
Output is correct |
60 |
Correct |
2 ms |
344 KB |
Output is correct |
61 |
Correct |
163 ms |
1876 KB |
Output is correct |
62 |
Correct |
156 ms |
2012 KB |
Output is correct |
63 |
Correct |
143 ms |
2004 KB |
Output is correct |
64 |
Correct |
142 ms |
1856 KB |
Output is correct |
65 |
Correct |
169 ms |
1616 KB |
Output is correct |
66 |
Correct |
160 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
604 KB |
Output is correct |
2 |
Correct |
4 ms |
860 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
860 KB |
Output is correct |
6 |
Correct |
6 ms |
860 KB |
Output is correct |
7 |
Correct |
5 ms |
860 KB |
Output is correct |
8 |
Correct |
8 ms |
1036 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
17 ms |
1116 KB |
Output is correct |
11 |
Correct |
17 ms |
1112 KB |
Output is correct |
12 |
Correct |
17 ms |
1116 KB |
Output is correct |
13 |
Correct |
14 ms |
1116 KB |
Output is correct |
14 |
Correct |
16 ms |
1128 KB |
Output is correct |
15 |
Correct |
15 ms |
1376 KB |
Output is correct |
16 |
Correct |
16 ms |
1124 KB |
Output is correct |
17 |
Correct |
12 ms |
1040 KB |
Output is correct |
18 |
Correct |
15 ms |
1132 KB |
Output is correct |
19 |
Correct |
14 ms |
1368 KB |
Output is correct |
20 |
Correct |
17 ms |
1116 KB |
Output is correct |
21 |
Correct |
34 ms |
1116 KB |
Output is correct |
22 |
Correct |
39 ms |
1300 KB |
Output is correct |
23 |
Correct |
27 ms |
1112 KB |
Output is correct |
24 |
Correct |
53 ms |
1300 KB |
Output is correct |
25 |
Correct |
50 ms |
1312 KB |
Output is correct |
26 |
Correct |
52 ms |
1112 KB |
Output is correct |
27 |
Correct |
53 ms |
1116 KB |
Output is correct |
28 |
Correct |
52 ms |
1112 KB |
Output is correct |
29 |
Correct |
52 ms |
1284 KB |
Output is correct |
30 |
Correct |
52 ms |
1112 KB |
Output is correct |
31 |
Correct |
52 ms |
1112 KB |
Output is correct |
32 |
Correct |
52 ms |
1116 KB |
Output is correct |
33 |
Correct |
52 ms |
1112 KB |
Output is correct |
34 |
Correct |
53 ms |
1112 KB |
Output is correct |
35 |
Correct |
52 ms |
1112 KB |
Output is correct |
36 |
Correct |
52 ms |
1112 KB |
Output is correct |
37 |
Correct |
101 ms |
1380 KB |
Output is correct |
38 |
Correct |
103 ms |
1376 KB |
Output is correct |
39 |
Correct |
133 ms |
1616 KB |
Output is correct |
40 |
Correct |
135 ms |
1620 KB |
Output is correct |
41 |
Correct |
152 ms |
1372 KB |
Output is correct |
42 |
Correct |
127 ms |
1384 KB |
Output is correct |
43 |
Correct |
119 ms |
1616 KB |
Output is correct |
44 |
Correct |
119 ms |
1616 KB |
Output is correct |
45 |
Correct |
124 ms |
1652 KB |
Output is correct |
46 |
Correct |
146 ms |
1620 KB |
Output is correct |
47 |
Correct |
124 ms |
1508 KB |
Output is correct |
48 |
Correct |
123 ms |
1616 KB |
Output is correct |
49 |
Correct |
131 ms |
1368 KB |
Output is correct |
50 |
Correct |
124 ms |
1380 KB |
Output is correct |
51 |
Correct |
2 ms |
348 KB |
Output is correct |
52 |
Correct |
130 ms |
1732 KB |
Output is correct |
53 |
Correct |
146 ms |
1748 KB |
Output is correct |
54 |
Correct |
176 ms |
1744 KB |
Output is correct |
55 |
Correct |
159 ms |
1876 KB |
Output is correct |
56 |
Correct |
148 ms |
1744 KB |
Output is correct |
57 |
Correct |
155 ms |
2128 KB |
Output is correct |
58 |
Correct |
168 ms |
1724 KB |
Output is correct |
59 |
Correct |
164 ms |
1748 KB |
Output is correct |
60 |
Correct |
2 ms |
344 KB |
Output is correct |
61 |
Correct |
163 ms |
1876 KB |
Output is correct |
62 |
Correct |
156 ms |
2012 KB |
Output is correct |
63 |
Correct |
143 ms |
2004 KB |
Output is correct |
64 |
Correct |
142 ms |
1856 KB |
Output is correct |
65 |
Correct |
169 ms |
1616 KB |
Output is correct |
66 |
Correct |
160 ms |
1488 KB |
Output is correct |
67 |
Correct |
186 ms |
1876 KB |
Output is correct |
68 |
Correct |
3 ms |
348 KB |
Output is correct |
69 |
Correct |
199 ms |
2424 KB |
Output is correct |
70 |
Correct |
215 ms |
2112 KB |
Output is correct |
71 |
Correct |
216 ms |
2112 KB |
Output is correct |
72 |
Correct |
219 ms |
1472 KB |
Output is correct |
73 |
Correct |
211 ms |
1468 KB |
Output is correct |
74 |
Correct |
186 ms |
2640 KB |
Output is correct |
75 |
Correct |
198 ms |
2364 KB |
Output is correct |
76 |
Correct |
187 ms |
2512 KB |
Output is correct |
77 |
Correct |
212 ms |
2624 KB |
Output is correct |