#include <bits/stdc++.h>
const int MAXN = 323456;
using namespace std;
int a[MAXN], ans[MAXN], dp[MAXN], d[MAXN];
int main()
{
// freopen("bootfall.in", "r", stdin);
// freopen("bootfall.out", "w", stdout);
int n, i, j, sum = 0, x = 0;
cin >> n;
dp[0] = 1;
for (i = 1; i <= n; i++){
cin >> a[i];
for (j = sum; j >= 0; j--) dp[j + a[i]] += dp[j];
sum += a[i];
}
if (sum % 2 == 1 || dp[sum / 2] == 0) return cout << 0 << endl, 0;
for (j = 0; j <= sum; j++) d[j] = dp[j];
for (i = 1; i <= n; i++){
for (j = 0; j <= sum; j++) {
d[j + a[i]] -= d[j];
x = abs(sum - j - a[i] - j);
if (d[j] != 0 && ans[x] == i - 1) ans[x] = i;
d[j] = dp[j];
}
}
vector < int > v;
for (i = 0; i <= sum; i++) if (ans[i] == n) v.push_back(i);
cout << v.size() << endl;
for (i = 0; i < v.size(); i++) cout << v[i] << " ";
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < v.size(); i++) cout << v[i] << " ";
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
10 |
Correct |
0 ms |
7068 KB |
Output is correct |
11 |
Correct |
0 ms |
7068 KB |
Output is correct |
12 |
Correct |
0 ms |
7068 KB |
Output is correct |
13 |
Correct |
0 ms |
7068 KB |
Output is correct |
14 |
Correct |
0 ms |
7068 KB |
Output is correct |
15 |
Correct |
0 ms |
7068 KB |
Output is correct |
16 |
Correct |
0 ms |
7068 KB |
Output is correct |
17 |
Correct |
0 ms |
7068 KB |
Output is correct |
18 |
Correct |
0 ms |
7068 KB |
Output is correct |
19 |
Correct |
0 ms |
7068 KB |
Output is correct |
20 |
Correct |
0 ms |
7068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
10 |
Correct |
0 ms |
7068 KB |
Output is correct |
11 |
Correct |
0 ms |
7068 KB |
Output is correct |
12 |
Correct |
0 ms |
7068 KB |
Output is correct |
13 |
Correct |
0 ms |
7068 KB |
Output is correct |
14 |
Correct |
0 ms |
7068 KB |
Output is correct |
15 |
Correct |
0 ms |
7068 KB |
Output is correct |
16 |
Correct |
0 ms |
7068 KB |
Output is correct |
17 |
Correct |
0 ms |
7068 KB |
Output is correct |
18 |
Correct |
0 ms |
7068 KB |
Output is correct |
19 |
Correct |
0 ms |
7068 KB |
Output is correct |
20 |
Correct |
0 ms |
7068 KB |
Output is correct |
21 |
Correct |
0 ms |
7068 KB |
Output is correct |
22 |
Correct |
0 ms |
7068 KB |
Output is correct |
23 |
Correct |
0 ms |
7068 KB |
Output is correct |
24 |
Correct |
0 ms |
7068 KB |
Output is correct |
25 |
Correct |
3 ms |
7068 KB |
Output is correct |
26 |
Correct |
3 ms |
7068 KB |
Output is correct |
27 |
Correct |
3 ms |
7068 KB |
Output is correct |
28 |
Correct |
3 ms |
7068 KB |
Output is correct |
29 |
Correct |
3 ms |
7068 KB |
Output is correct |
30 |
Correct |
0 ms |
7068 KB |
Output is correct |
31 |
Correct |
3 ms |
7068 KB |
Output is correct |
32 |
Correct |
0 ms |
7068 KB |
Output is correct |
33 |
Correct |
3 ms |
7068 KB |
Output is correct |
34 |
Correct |
0 ms |
7068 KB |
Output is correct |
35 |
Correct |
3 ms |
7068 KB |
Output is correct |
36 |
Correct |
3 ms |
7068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
10 |
Correct |
0 ms |
7068 KB |
Output is correct |
11 |
Correct |
0 ms |
7068 KB |
Output is correct |
12 |
Correct |
0 ms |
7068 KB |
Output is correct |
13 |
Correct |
0 ms |
7068 KB |
Output is correct |
14 |
Correct |
0 ms |
7068 KB |
Output is correct |
15 |
Correct |
0 ms |
7068 KB |
Output is correct |
16 |
Correct |
0 ms |
7068 KB |
Output is correct |
17 |
Correct |
0 ms |
7068 KB |
Output is correct |
18 |
Correct |
0 ms |
7068 KB |
Output is correct |
19 |
Correct |
0 ms |
7068 KB |
Output is correct |
20 |
Correct |
0 ms |
7068 KB |
Output is correct |
21 |
Correct |
0 ms |
7068 KB |
Output is correct |
22 |
Correct |
0 ms |
7068 KB |
Output is correct |
23 |
Correct |
0 ms |
7068 KB |
Output is correct |
24 |
Correct |
0 ms |
7068 KB |
Output is correct |
25 |
Correct |
3 ms |
7068 KB |
Output is correct |
26 |
Correct |
3 ms |
7068 KB |
Output is correct |
27 |
Correct |
3 ms |
7068 KB |
Output is correct |
28 |
Correct |
3 ms |
7068 KB |
Output is correct |
29 |
Correct |
3 ms |
7068 KB |
Output is correct |
30 |
Correct |
0 ms |
7068 KB |
Output is correct |
31 |
Correct |
3 ms |
7068 KB |
Output is correct |
32 |
Correct |
0 ms |
7068 KB |
Output is correct |
33 |
Correct |
3 ms |
7068 KB |
Output is correct |
34 |
Correct |
0 ms |
7068 KB |
Output is correct |
35 |
Correct |
3 ms |
7068 KB |
Output is correct |
36 |
Correct |
3 ms |
7068 KB |
Output is correct |
37 |
Correct |
13 ms |
7208 KB |
Output is correct |
38 |
Correct |
16 ms |
7208 KB |
Output is correct |
39 |
Correct |
33 ms |
7068 KB |
Output is correct |
40 |
Correct |
33 ms |
7208 KB |
Output is correct |
41 |
Correct |
56 ms |
7068 KB |
Output is correct |
42 |
Correct |
23 ms |
7208 KB |
Output is correct |
43 |
Correct |
43 ms |
7340 KB |
Output is correct |
44 |
Correct |
49 ms |
7340 KB |
Output is correct |
45 |
Correct |
49 ms |
7340 KB |
Output is correct |
46 |
Correct |
23 ms |
7068 KB |
Output is correct |
47 |
Correct |
26 ms |
7208 KB |
Output is correct |
48 |
Correct |
59 ms |
7340 KB |
Output is correct |
49 |
Correct |
49 ms |
7208 KB |
Output is correct |
50 |
Correct |
23 ms |
7208 KB |
Output is correct |
51 |
Correct |
0 ms |
7068 KB |
Output is correct |
52 |
Correct |
69 ms |
7340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
10 |
Correct |
0 ms |
7068 KB |
Output is correct |
11 |
Correct |
0 ms |
7068 KB |
Output is correct |
12 |
Correct |
0 ms |
7068 KB |
Output is correct |
13 |
Correct |
0 ms |
7068 KB |
Output is correct |
14 |
Correct |
0 ms |
7068 KB |
Output is correct |
15 |
Correct |
0 ms |
7068 KB |
Output is correct |
16 |
Correct |
0 ms |
7068 KB |
Output is correct |
17 |
Correct |
0 ms |
7068 KB |
Output is correct |
18 |
Correct |
0 ms |
7068 KB |
Output is correct |
19 |
Correct |
0 ms |
7068 KB |
Output is correct |
20 |
Correct |
0 ms |
7068 KB |
Output is correct |
21 |
Correct |
0 ms |
7068 KB |
Output is correct |
22 |
Correct |
0 ms |
7068 KB |
Output is correct |
23 |
Correct |
0 ms |
7068 KB |
Output is correct |
24 |
Correct |
0 ms |
7068 KB |
Output is correct |
25 |
Correct |
3 ms |
7068 KB |
Output is correct |
26 |
Correct |
3 ms |
7068 KB |
Output is correct |
27 |
Correct |
3 ms |
7068 KB |
Output is correct |
28 |
Correct |
3 ms |
7068 KB |
Output is correct |
29 |
Correct |
3 ms |
7068 KB |
Output is correct |
30 |
Correct |
0 ms |
7068 KB |
Output is correct |
31 |
Correct |
3 ms |
7068 KB |
Output is correct |
32 |
Correct |
0 ms |
7068 KB |
Output is correct |
33 |
Correct |
3 ms |
7068 KB |
Output is correct |
34 |
Correct |
0 ms |
7068 KB |
Output is correct |
35 |
Correct |
3 ms |
7068 KB |
Output is correct |
36 |
Correct |
3 ms |
7068 KB |
Output is correct |
37 |
Correct |
13 ms |
7208 KB |
Output is correct |
38 |
Correct |
16 ms |
7208 KB |
Output is correct |
39 |
Correct |
33 ms |
7068 KB |
Output is correct |
40 |
Correct |
33 ms |
7208 KB |
Output is correct |
41 |
Correct |
56 ms |
7068 KB |
Output is correct |
42 |
Correct |
23 ms |
7208 KB |
Output is correct |
43 |
Correct |
43 ms |
7340 KB |
Output is correct |
44 |
Correct |
49 ms |
7340 KB |
Output is correct |
45 |
Correct |
49 ms |
7340 KB |
Output is correct |
46 |
Correct |
23 ms |
7068 KB |
Output is correct |
47 |
Correct |
26 ms |
7208 KB |
Output is correct |
48 |
Correct |
59 ms |
7340 KB |
Output is correct |
49 |
Correct |
49 ms |
7208 KB |
Output is correct |
50 |
Correct |
23 ms |
7208 KB |
Output is correct |
51 |
Correct |
0 ms |
7068 KB |
Output is correct |
52 |
Correct |
69 ms |
7340 KB |
Output is correct |
53 |
Correct |
49 ms |
7340 KB |
Output is correct |
54 |
Correct |
79 ms |
7340 KB |
Output is correct |
55 |
Correct |
129 ms |
7536 KB |
Output is correct |
56 |
Correct |
63 ms |
7340 KB |
Output is correct |
57 |
Correct |
139 ms |
7536 KB |
Output is correct |
58 |
Correct |
69 ms |
7340 KB |
Output is correct |
59 |
Correct |
86 ms |
7536 KB |
Output is correct |
60 |
Correct |
9 ms |
7068 KB |
Output is correct |
61 |
Correct |
109 ms |
7536 KB |
Output is correct |
62 |
Correct |
103 ms |
7536 KB |
Output is correct |
63 |
Correct |
116 ms |
7536 KB |
Output is correct |
64 |
Correct |
123 ms |
7536 KB |
Output is correct |
65 |
Correct |
56 ms |
7068 KB |
Output is correct |
66 |
Correct |
39 ms |
7208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
7068 KB |
Output is correct |
2 |
Correct |
0 ms |
7068 KB |
Output is correct |
3 |
Correct |
0 ms |
7068 KB |
Output is correct |
4 |
Correct |
0 ms |
7068 KB |
Output is correct |
5 |
Correct |
0 ms |
7068 KB |
Output is correct |
6 |
Correct |
0 ms |
7068 KB |
Output is correct |
7 |
Correct |
0 ms |
7068 KB |
Output is correct |
8 |
Correct |
0 ms |
7068 KB |
Output is correct |
9 |
Correct |
0 ms |
7068 KB |
Output is correct |
10 |
Correct |
0 ms |
7068 KB |
Output is correct |
11 |
Correct |
0 ms |
7068 KB |
Output is correct |
12 |
Correct |
0 ms |
7068 KB |
Output is correct |
13 |
Correct |
0 ms |
7068 KB |
Output is correct |
14 |
Correct |
0 ms |
7068 KB |
Output is correct |
15 |
Correct |
0 ms |
7068 KB |
Output is correct |
16 |
Correct |
0 ms |
7068 KB |
Output is correct |
17 |
Correct |
0 ms |
7068 KB |
Output is correct |
18 |
Correct |
0 ms |
7068 KB |
Output is correct |
19 |
Correct |
0 ms |
7068 KB |
Output is correct |
20 |
Correct |
0 ms |
7068 KB |
Output is correct |
21 |
Correct |
0 ms |
7068 KB |
Output is correct |
22 |
Correct |
0 ms |
7068 KB |
Output is correct |
23 |
Correct |
0 ms |
7068 KB |
Output is correct |
24 |
Correct |
0 ms |
7068 KB |
Output is correct |
25 |
Correct |
3 ms |
7068 KB |
Output is correct |
26 |
Correct |
3 ms |
7068 KB |
Output is correct |
27 |
Correct |
3 ms |
7068 KB |
Output is correct |
28 |
Correct |
3 ms |
7068 KB |
Output is correct |
29 |
Correct |
3 ms |
7068 KB |
Output is correct |
30 |
Correct |
0 ms |
7068 KB |
Output is correct |
31 |
Correct |
3 ms |
7068 KB |
Output is correct |
32 |
Correct |
0 ms |
7068 KB |
Output is correct |
33 |
Correct |
3 ms |
7068 KB |
Output is correct |
34 |
Correct |
0 ms |
7068 KB |
Output is correct |
35 |
Correct |
3 ms |
7068 KB |
Output is correct |
36 |
Correct |
3 ms |
7068 KB |
Output is correct |
37 |
Correct |
13 ms |
7208 KB |
Output is correct |
38 |
Correct |
16 ms |
7208 KB |
Output is correct |
39 |
Correct |
33 ms |
7068 KB |
Output is correct |
40 |
Correct |
33 ms |
7208 KB |
Output is correct |
41 |
Correct |
56 ms |
7068 KB |
Output is correct |
42 |
Correct |
23 ms |
7208 KB |
Output is correct |
43 |
Correct |
43 ms |
7340 KB |
Output is correct |
44 |
Correct |
49 ms |
7340 KB |
Output is correct |
45 |
Correct |
49 ms |
7340 KB |
Output is correct |
46 |
Correct |
23 ms |
7068 KB |
Output is correct |
47 |
Correct |
26 ms |
7208 KB |
Output is correct |
48 |
Correct |
59 ms |
7340 KB |
Output is correct |
49 |
Correct |
49 ms |
7208 KB |
Output is correct |
50 |
Correct |
23 ms |
7208 KB |
Output is correct |
51 |
Correct |
0 ms |
7068 KB |
Output is correct |
52 |
Correct |
69 ms |
7340 KB |
Output is correct |
53 |
Correct |
49 ms |
7340 KB |
Output is correct |
54 |
Correct |
79 ms |
7340 KB |
Output is correct |
55 |
Correct |
129 ms |
7536 KB |
Output is correct |
56 |
Correct |
63 ms |
7340 KB |
Output is correct |
57 |
Correct |
139 ms |
7536 KB |
Output is correct |
58 |
Correct |
69 ms |
7340 KB |
Output is correct |
59 |
Correct |
86 ms |
7536 KB |
Output is correct |
60 |
Correct |
9 ms |
7068 KB |
Output is correct |
61 |
Correct |
109 ms |
7536 KB |
Output is correct |
62 |
Correct |
103 ms |
7536 KB |
Output is correct |
63 |
Correct |
116 ms |
7536 KB |
Output is correct |
64 |
Correct |
123 ms |
7536 KB |
Output is correct |
65 |
Correct |
56 ms |
7068 KB |
Output is correct |
66 |
Correct |
39 ms |
7208 KB |
Output is correct |
67 |
Correct |
109 ms |
7536 KB |
Output is correct |
68 |
Correct |
36 ms |
7068 KB |
Output is correct |
69 |
Correct |
353 ms |
7920 KB |
Output is correct |
70 |
Correct |
229 ms |
7536 KB |
Output is correct |
71 |
Correct |
213 ms |
7536 KB |
Output is correct |
72 |
Correct |
209 ms |
7068 KB |
Output is correct |
73 |
Correct |
236 ms |
7068 KB |
Output is correct |
74 |
Correct |
353 ms |
7920 KB |
Output is correct |
75 |
Correct |
276 ms |
7920 KB |
Output is correct |
76 |
Correct |
423 ms |
7920 KB |
Output is correct |
77 |
Correct |
376 ms |
7920 KB |
Output is correct |