#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll
const int N = 505;
const int Tima = (500 * 500) + 5;
int n, sum, dp[Tima], a[N];
bool can[Tima];
vector <int> ans;
void add(int x) {
sum += x;
for(int i = sum; i >= x; --i) {
dp[i] += dp[i - x];
}
}
void del(int x) {
for(int i = x; i <= sum; ++i) {
dp[i] -= dp[i - x];
}
sum -= x;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
dp[0] = 1;
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
add(a[i]);
}
if((sum % 2 == 1) || (dp[sum / 2] == 0)) {
puts("0");
return 0;
}
for(int i = 0; i < Tima; ++i)
can[i] = true;
for(int i = 1; i <= n; ++i) {
del(a[i]);
for(int x = 0; x < Tima; ++x) {
if(((sum + x) % 2 == 1) || (dp[(sum + x) / 2] == 0)) {
can[x] = 0;
}
}
add(a[i]);
}
for(int i = 0; i < Tima; ++i) {
if(can[i])
ans.pb(i);
}
cout << sz(ans) <<'\n';
for(int it : ans)
cout << it <<' ';
return 0;
}
/*
If you only do what you can do,
You will never be more than you are now!
We must all suffer from one of two pains: the pain of discipline or the pain of regret.
The difference is discipline weighs grams while regret weighs tons.
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
15 ms |
504 KB |
Output is correct |
13 |
Correct |
13 ms |
632 KB |
Output is correct |
14 |
Correct |
14 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
15 ms |
508 KB |
Output is correct |
17 |
Correct |
10 ms |
632 KB |
Output is correct |
18 |
Correct |
13 ms |
520 KB |
Output is correct |
19 |
Correct |
13 ms |
632 KB |
Output is correct |
20 |
Correct |
15 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
15 ms |
504 KB |
Output is correct |
13 |
Correct |
13 ms |
632 KB |
Output is correct |
14 |
Correct |
14 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
15 ms |
508 KB |
Output is correct |
17 |
Correct |
10 ms |
632 KB |
Output is correct |
18 |
Correct |
13 ms |
520 KB |
Output is correct |
19 |
Correct |
13 ms |
632 KB |
Output is correct |
20 |
Correct |
15 ms |
760 KB |
Output is correct |
21 |
Correct |
28 ms |
632 KB |
Output is correct |
22 |
Correct |
32 ms |
648 KB |
Output is correct |
23 |
Correct |
23 ms |
760 KB |
Output is correct |
24 |
Correct |
41 ms |
676 KB |
Output is correct |
25 |
Correct |
41 ms |
636 KB |
Output is correct |
26 |
Correct |
44 ms |
732 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
44 ms |
700 KB |
Output is correct |
29 |
Correct |
44 ms |
632 KB |
Output is correct |
30 |
Correct |
43 ms |
632 KB |
Output is correct |
31 |
Correct |
43 ms |
632 KB |
Output is correct |
32 |
Correct |
43 ms |
792 KB |
Output is correct |
33 |
Correct |
44 ms |
632 KB |
Output is correct |
34 |
Correct |
43 ms |
668 KB |
Output is correct |
35 |
Correct |
44 ms |
672 KB |
Output is correct |
36 |
Correct |
43 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
15 ms |
504 KB |
Output is correct |
13 |
Correct |
13 ms |
632 KB |
Output is correct |
14 |
Correct |
14 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
15 ms |
508 KB |
Output is correct |
17 |
Correct |
10 ms |
632 KB |
Output is correct |
18 |
Correct |
13 ms |
520 KB |
Output is correct |
19 |
Correct |
13 ms |
632 KB |
Output is correct |
20 |
Correct |
15 ms |
760 KB |
Output is correct |
21 |
Correct |
28 ms |
632 KB |
Output is correct |
22 |
Correct |
32 ms |
648 KB |
Output is correct |
23 |
Correct |
23 ms |
760 KB |
Output is correct |
24 |
Correct |
41 ms |
676 KB |
Output is correct |
25 |
Correct |
41 ms |
636 KB |
Output is correct |
26 |
Correct |
44 ms |
732 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
44 ms |
700 KB |
Output is correct |
29 |
Correct |
44 ms |
632 KB |
Output is correct |
30 |
Correct |
43 ms |
632 KB |
Output is correct |
31 |
Correct |
43 ms |
632 KB |
Output is correct |
32 |
Correct |
43 ms |
792 KB |
Output is correct |
33 |
Correct |
44 ms |
632 KB |
Output is correct |
34 |
Correct |
43 ms |
668 KB |
Output is correct |
35 |
Correct |
44 ms |
672 KB |
Output is correct |
36 |
Correct |
43 ms |
632 KB |
Output is correct |
37 |
Correct |
87 ms |
832 KB |
Output is correct |
38 |
Correct |
88 ms |
836 KB |
Output is correct |
39 |
Correct |
125 ms |
988 KB |
Output is correct |
40 |
Correct |
124 ms |
888 KB |
Output is correct |
41 |
Correct |
139 ms |
888 KB |
Output is correct |
42 |
Correct |
115 ms |
912 KB |
Output is correct |
43 |
Correct |
123 ms |
1144 KB |
Output is correct |
44 |
Correct |
124 ms |
1144 KB |
Output is correct |
45 |
Correct |
126 ms |
1244 KB |
Output is correct |
46 |
Correct |
126 ms |
760 KB |
Output is correct |
47 |
Correct |
114 ms |
988 KB |
Output is correct |
48 |
Correct |
127 ms |
1144 KB |
Output is correct |
49 |
Correct |
129 ms |
888 KB |
Output is correct |
50 |
Correct |
114 ms |
988 KB |
Output is correct |
51 |
Correct |
4 ms |
508 KB |
Output is correct |
52 |
Correct |
142 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
15 ms |
504 KB |
Output is correct |
13 |
Correct |
13 ms |
632 KB |
Output is correct |
14 |
Correct |
14 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
15 ms |
508 KB |
Output is correct |
17 |
Correct |
10 ms |
632 KB |
Output is correct |
18 |
Correct |
13 ms |
520 KB |
Output is correct |
19 |
Correct |
13 ms |
632 KB |
Output is correct |
20 |
Correct |
15 ms |
760 KB |
Output is correct |
21 |
Correct |
28 ms |
632 KB |
Output is correct |
22 |
Correct |
32 ms |
648 KB |
Output is correct |
23 |
Correct |
23 ms |
760 KB |
Output is correct |
24 |
Correct |
41 ms |
676 KB |
Output is correct |
25 |
Correct |
41 ms |
636 KB |
Output is correct |
26 |
Correct |
44 ms |
732 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
44 ms |
700 KB |
Output is correct |
29 |
Correct |
44 ms |
632 KB |
Output is correct |
30 |
Correct |
43 ms |
632 KB |
Output is correct |
31 |
Correct |
43 ms |
632 KB |
Output is correct |
32 |
Correct |
43 ms |
792 KB |
Output is correct |
33 |
Correct |
44 ms |
632 KB |
Output is correct |
34 |
Correct |
43 ms |
668 KB |
Output is correct |
35 |
Correct |
44 ms |
672 KB |
Output is correct |
36 |
Correct |
43 ms |
632 KB |
Output is correct |
37 |
Correct |
87 ms |
832 KB |
Output is correct |
38 |
Correct |
88 ms |
836 KB |
Output is correct |
39 |
Correct |
125 ms |
988 KB |
Output is correct |
40 |
Correct |
124 ms |
888 KB |
Output is correct |
41 |
Correct |
139 ms |
888 KB |
Output is correct |
42 |
Correct |
115 ms |
912 KB |
Output is correct |
43 |
Correct |
123 ms |
1144 KB |
Output is correct |
44 |
Correct |
124 ms |
1144 KB |
Output is correct |
45 |
Correct |
126 ms |
1244 KB |
Output is correct |
46 |
Correct |
126 ms |
760 KB |
Output is correct |
47 |
Correct |
114 ms |
988 KB |
Output is correct |
48 |
Correct |
127 ms |
1144 KB |
Output is correct |
49 |
Correct |
129 ms |
888 KB |
Output is correct |
50 |
Correct |
114 ms |
988 KB |
Output is correct |
51 |
Correct |
4 ms |
508 KB |
Output is correct |
52 |
Correct |
142 ms |
1244 KB |
Output is correct |
53 |
Correct |
142 ms |
1116 KB |
Output is correct |
54 |
Correct |
171 ms |
1244 KB |
Output is correct |
55 |
Correct |
215 ms |
1700 KB |
Output is correct |
56 |
Correct |
154 ms |
1244 KB |
Output is correct |
57 |
Correct |
209 ms |
1756 KB |
Output is correct |
58 |
Correct |
177 ms |
1372 KB |
Output is correct |
59 |
Correct |
185 ms |
1452 KB |
Output is correct |
60 |
Correct |
10 ms |
632 KB |
Output is correct |
61 |
Correct |
198 ms |
1500 KB |
Output is correct |
62 |
Correct |
182 ms |
1528 KB |
Output is correct |
63 |
Correct |
186 ms |
1624 KB |
Output is correct |
64 |
Correct |
188 ms |
1540 KB |
Output is correct |
65 |
Correct |
162 ms |
888 KB |
Output is correct |
66 |
Correct |
158 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
6 ms |
760 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
632 KB |
Output is correct |
5 |
Correct |
8 ms |
760 KB |
Output is correct |
6 |
Correct |
6 ms |
632 KB |
Output is correct |
7 |
Correct |
6 ms |
632 KB |
Output is correct |
8 |
Correct |
8 ms |
632 KB |
Output is correct |
9 |
Correct |
7 ms |
632 KB |
Output is correct |
10 |
Correct |
15 ms |
632 KB |
Output is correct |
11 |
Correct |
15 ms |
632 KB |
Output is correct |
12 |
Correct |
15 ms |
504 KB |
Output is correct |
13 |
Correct |
13 ms |
632 KB |
Output is correct |
14 |
Correct |
14 ms |
632 KB |
Output is correct |
15 |
Correct |
14 ms |
632 KB |
Output is correct |
16 |
Correct |
15 ms |
508 KB |
Output is correct |
17 |
Correct |
10 ms |
632 KB |
Output is correct |
18 |
Correct |
13 ms |
520 KB |
Output is correct |
19 |
Correct |
13 ms |
632 KB |
Output is correct |
20 |
Correct |
15 ms |
760 KB |
Output is correct |
21 |
Correct |
28 ms |
632 KB |
Output is correct |
22 |
Correct |
32 ms |
648 KB |
Output is correct |
23 |
Correct |
23 ms |
760 KB |
Output is correct |
24 |
Correct |
41 ms |
676 KB |
Output is correct |
25 |
Correct |
41 ms |
636 KB |
Output is correct |
26 |
Correct |
44 ms |
732 KB |
Output is correct |
27 |
Correct |
44 ms |
632 KB |
Output is correct |
28 |
Correct |
44 ms |
700 KB |
Output is correct |
29 |
Correct |
44 ms |
632 KB |
Output is correct |
30 |
Correct |
43 ms |
632 KB |
Output is correct |
31 |
Correct |
43 ms |
632 KB |
Output is correct |
32 |
Correct |
43 ms |
792 KB |
Output is correct |
33 |
Correct |
44 ms |
632 KB |
Output is correct |
34 |
Correct |
43 ms |
668 KB |
Output is correct |
35 |
Correct |
44 ms |
672 KB |
Output is correct |
36 |
Correct |
43 ms |
632 KB |
Output is correct |
37 |
Correct |
87 ms |
832 KB |
Output is correct |
38 |
Correct |
88 ms |
836 KB |
Output is correct |
39 |
Correct |
125 ms |
988 KB |
Output is correct |
40 |
Correct |
124 ms |
888 KB |
Output is correct |
41 |
Correct |
139 ms |
888 KB |
Output is correct |
42 |
Correct |
115 ms |
912 KB |
Output is correct |
43 |
Correct |
123 ms |
1144 KB |
Output is correct |
44 |
Correct |
124 ms |
1144 KB |
Output is correct |
45 |
Correct |
126 ms |
1244 KB |
Output is correct |
46 |
Correct |
126 ms |
760 KB |
Output is correct |
47 |
Correct |
114 ms |
988 KB |
Output is correct |
48 |
Correct |
127 ms |
1144 KB |
Output is correct |
49 |
Correct |
129 ms |
888 KB |
Output is correct |
50 |
Correct |
114 ms |
988 KB |
Output is correct |
51 |
Correct |
4 ms |
508 KB |
Output is correct |
52 |
Correct |
142 ms |
1244 KB |
Output is correct |
53 |
Correct |
142 ms |
1116 KB |
Output is correct |
54 |
Correct |
171 ms |
1244 KB |
Output is correct |
55 |
Correct |
215 ms |
1700 KB |
Output is correct |
56 |
Correct |
154 ms |
1244 KB |
Output is correct |
57 |
Correct |
209 ms |
1756 KB |
Output is correct |
58 |
Correct |
177 ms |
1372 KB |
Output is correct |
59 |
Correct |
185 ms |
1452 KB |
Output is correct |
60 |
Correct |
10 ms |
632 KB |
Output is correct |
61 |
Correct |
198 ms |
1500 KB |
Output is correct |
62 |
Correct |
182 ms |
1528 KB |
Output is correct |
63 |
Correct |
186 ms |
1624 KB |
Output is correct |
64 |
Correct |
188 ms |
1540 KB |
Output is correct |
65 |
Correct |
162 ms |
888 KB |
Output is correct |
66 |
Correct |
158 ms |
840 KB |
Output is correct |
67 |
Correct |
209 ms |
1528 KB |
Output is correct |
68 |
Correct |
22 ms |
760 KB |
Output is correct |
69 |
Correct |
372 ms |
2608 KB |
Output is correct |
70 |
Correct |
307 ms |
2036 KB |
Output is correct |
71 |
Correct |
303 ms |
1788 KB |
Output is correct |
72 |
Correct |
305 ms |
1144 KB |
Output is correct |
73 |
Correct |
294 ms |
1144 KB |
Output is correct |
74 |
Correct |
386 ms |
2796 KB |
Output is correct |
75 |
Correct |
344 ms |
2420 KB |
Output is correct |
76 |
Correct |
407 ms |
2804 KB |
Output is correct |
77 |
Correct |
394 ms |
2932 KB |
Output is correct |