#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define N 555
#define pp pair<int, int>
#define bit(S, i) (((S) >> i) & 1)
#define IO cin.tie(NULL);cout.tie(NULL);
#define taskname "BOOTFALL"
using namespace std;
int n, a[N];
long long dp[N * N], newDp[N * N], cnt[N * N];
vector<int> res;
int main() {
// freopen(taskname".inp","r",stdin);
// freopen(taskname".out","w",stdout);
IO;
scanf("%d", &n);
int all = 0;
FOR(i, 1, n) scanf("%d", &a[i]);
FOR(i, 1, n) all += a[i];
int total = 0;
dp[0] = 1;
FOR(i, 1, n) {
total += a[i];
FORD(S, all, a[i]) {
if (dp[S - a[i]]) {
dp[S] += dp[S - a[i]];
}
}
}
if (all % 2 == 1 || dp[all / 2] == 0) {
printf("0");return 0;
}
// FOR(S, 0, all) if (dp[0][S]) cerr << S << ':' << dp[0][S] << endl;
FOR(i, 1, n) {
FOR(S, 0, all) newDp[S] = dp[S];
FOR(S, a[i], all) newDp[S] -= newDp[S - a[i]];
FOR(value, 1, all) {
if ((all + value - a[i]) % 2 == 1 || all - a[i] < value) {
continue;
}
int newMid = (all - a[i] + value) / 2;
if (newDp[newMid - value] == 0) {
continue;
}
cnt[value]++;
}
}
FOR(value, 1, all) {
if (cnt[value] == n) {
res.push_back(value);
}
}
printf("%d\n", res.size());
for (int value : res) printf("%d ", value);
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:57:30: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
printf("%d\n", res.size());
^
bootfall.cpp:20:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
bootfall.cpp:22:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
FOR(i, 1, n) scanf("%d", &a[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
10 |
Correct |
0 ms |
9236 KB |
Output is correct |
11 |
Correct |
0 ms |
9236 KB |
Output is correct |
12 |
Correct |
0 ms |
9236 KB |
Output is correct |
13 |
Correct |
0 ms |
9236 KB |
Output is correct |
14 |
Correct |
0 ms |
9236 KB |
Output is correct |
15 |
Correct |
0 ms |
9236 KB |
Output is correct |
16 |
Correct |
0 ms |
9236 KB |
Output is correct |
17 |
Correct |
0 ms |
9236 KB |
Output is correct |
18 |
Correct |
0 ms |
9236 KB |
Output is correct |
19 |
Correct |
0 ms |
9236 KB |
Output is correct |
20 |
Correct |
0 ms |
9236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
10 |
Correct |
0 ms |
9236 KB |
Output is correct |
11 |
Correct |
0 ms |
9236 KB |
Output is correct |
12 |
Correct |
0 ms |
9236 KB |
Output is correct |
13 |
Correct |
0 ms |
9236 KB |
Output is correct |
14 |
Correct |
0 ms |
9236 KB |
Output is correct |
15 |
Correct |
0 ms |
9236 KB |
Output is correct |
16 |
Correct |
0 ms |
9236 KB |
Output is correct |
17 |
Correct |
0 ms |
9236 KB |
Output is correct |
18 |
Correct |
0 ms |
9236 KB |
Output is correct |
19 |
Correct |
0 ms |
9236 KB |
Output is correct |
20 |
Correct |
0 ms |
9236 KB |
Output is correct |
21 |
Correct |
0 ms |
9236 KB |
Output is correct |
22 |
Correct |
0 ms |
9236 KB |
Output is correct |
23 |
Correct |
0 ms |
9236 KB |
Output is correct |
24 |
Correct |
3 ms |
9236 KB |
Output is correct |
25 |
Correct |
6 ms |
9236 KB |
Output is correct |
26 |
Correct |
3 ms |
9236 KB |
Output is correct |
27 |
Correct |
6 ms |
9236 KB |
Output is correct |
28 |
Correct |
3 ms |
9236 KB |
Output is correct |
29 |
Correct |
6 ms |
9236 KB |
Output is correct |
30 |
Correct |
3 ms |
9236 KB |
Output is correct |
31 |
Correct |
3 ms |
9236 KB |
Output is correct |
32 |
Correct |
0 ms |
9236 KB |
Output is correct |
33 |
Correct |
3 ms |
9236 KB |
Output is correct |
34 |
Correct |
3 ms |
9236 KB |
Output is correct |
35 |
Correct |
6 ms |
9236 KB |
Output is correct |
36 |
Correct |
3 ms |
9236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
10 |
Correct |
0 ms |
9236 KB |
Output is correct |
11 |
Correct |
0 ms |
9236 KB |
Output is correct |
12 |
Correct |
0 ms |
9236 KB |
Output is correct |
13 |
Correct |
0 ms |
9236 KB |
Output is correct |
14 |
Correct |
0 ms |
9236 KB |
Output is correct |
15 |
Correct |
0 ms |
9236 KB |
Output is correct |
16 |
Correct |
0 ms |
9236 KB |
Output is correct |
17 |
Correct |
0 ms |
9236 KB |
Output is correct |
18 |
Correct |
0 ms |
9236 KB |
Output is correct |
19 |
Correct |
0 ms |
9236 KB |
Output is correct |
20 |
Correct |
0 ms |
9236 KB |
Output is correct |
21 |
Correct |
0 ms |
9236 KB |
Output is correct |
22 |
Correct |
0 ms |
9236 KB |
Output is correct |
23 |
Correct |
0 ms |
9236 KB |
Output is correct |
24 |
Correct |
3 ms |
9236 KB |
Output is correct |
25 |
Correct |
6 ms |
9236 KB |
Output is correct |
26 |
Correct |
3 ms |
9236 KB |
Output is correct |
27 |
Correct |
6 ms |
9236 KB |
Output is correct |
28 |
Correct |
3 ms |
9236 KB |
Output is correct |
29 |
Correct |
6 ms |
9236 KB |
Output is correct |
30 |
Correct |
3 ms |
9236 KB |
Output is correct |
31 |
Correct |
3 ms |
9236 KB |
Output is correct |
32 |
Correct |
0 ms |
9236 KB |
Output is correct |
33 |
Correct |
3 ms |
9236 KB |
Output is correct |
34 |
Correct |
3 ms |
9236 KB |
Output is correct |
35 |
Correct |
6 ms |
9236 KB |
Output is correct |
36 |
Correct |
3 ms |
9236 KB |
Output is correct |
37 |
Correct |
39 ms |
9376 KB |
Output is correct |
38 |
Correct |
26 ms |
9376 KB |
Output is correct |
39 |
Correct |
73 ms |
9236 KB |
Output is correct |
40 |
Correct |
49 ms |
9376 KB |
Output is correct |
41 |
Correct |
123 ms |
9236 KB |
Output is correct |
42 |
Correct |
59 ms |
9376 KB |
Output is correct |
43 |
Correct |
69 ms |
9508 KB |
Output is correct |
44 |
Correct |
83 ms |
9508 KB |
Output is correct |
45 |
Correct |
93 ms |
9508 KB |
Output is correct |
46 |
Correct |
56 ms |
9236 KB |
Output is correct |
47 |
Correct |
69 ms |
9376 KB |
Output is correct |
48 |
Correct |
103 ms |
9508 KB |
Output is correct |
49 |
Correct |
86 ms |
9376 KB |
Output is correct |
50 |
Correct |
43 ms |
9376 KB |
Output is correct |
51 |
Correct |
9 ms |
9236 KB |
Output is correct |
52 |
Correct |
103 ms |
9508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
10 |
Correct |
0 ms |
9236 KB |
Output is correct |
11 |
Correct |
0 ms |
9236 KB |
Output is correct |
12 |
Correct |
0 ms |
9236 KB |
Output is correct |
13 |
Correct |
0 ms |
9236 KB |
Output is correct |
14 |
Correct |
0 ms |
9236 KB |
Output is correct |
15 |
Correct |
0 ms |
9236 KB |
Output is correct |
16 |
Correct |
0 ms |
9236 KB |
Output is correct |
17 |
Correct |
0 ms |
9236 KB |
Output is correct |
18 |
Correct |
0 ms |
9236 KB |
Output is correct |
19 |
Correct |
0 ms |
9236 KB |
Output is correct |
20 |
Correct |
0 ms |
9236 KB |
Output is correct |
21 |
Correct |
0 ms |
9236 KB |
Output is correct |
22 |
Correct |
0 ms |
9236 KB |
Output is correct |
23 |
Correct |
0 ms |
9236 KB |
Output is correct |
24 |
Correct |
3 ms |
9236 KB |
Output is correct |
25 |
Correct |
6 ms |
9236 KB |
Output is correct |
26 |
Correct |
3 ms |
9236 KB |
Output is correct |
27 |
Correct |
6 ms |
9236 KB |
Output is correct |
28 |
Correct |
3 ms |
9236 KB |
Output is correct |
29 |
Correct |
6 ms |
9236 KB |
Output is correct |
30 |
Correct |
3 ms |
9236 KB |
Output is correct |
31 |
Correct |
3 ms |
9236 KB |
Output is correct |
32 |
Correct |
0 ms |
9236 KB |
Output is correct |
33 |
Correct |
3 ms |
9236 KB |
Output is correct |
34 |
Correct |
3 ms |
9236 KB |
Output is correct |
35 |
Correct |
6 ms |
9236 KB |
Output is correct |
36 |
Correct |
3 ms |
9236 KB |
Output is correct |
37 |
Correct |
39 ms |
9376 KB |
Output is correct |
38 |
Correct |
26 ms |
9376 KB |
Output is correct |
39 |
Correct |
73 ms |
9236 KB |
Output is correct |
40 |
Correct |
49 ms |
9376 KB |
Output is correct |
41 |
Correct |
123 ms |
9236 KB |
Output is correct |
42 |
Correct |
59 ms |
9376 KB |
Output is correct |
43 |
Correct |
69 ms |
9508 KB |
Output is correct |
44 |
Correct |
83 ms |
9508 KB |
Output is correct |
45 |
Correct |
93 ms |
9508 KB |
Output is correct |
46 |
Correct |
56 ms |
9236 KB |
Output is correct |
47 |
Correct |
69 ms |
9376 KB |
Output is correct |
48 |
Correct |
103 ms |
9508 KB |
Output is correct |
49 |
Correct |
86 ms |
9376 KB |
Output is correct |
50 |
Correct |
43 ms |
9376 KB |
Output is correct |
51 |
Correct |
9 ms |
9236 KB |
Output is correct |
52 |
Correct |
103 ms |
9508 KB |
Output is correct |
53 |
Correct |
69 ms |
9508 KB |
Output is correct |
54 |
Correct |
103 ms |
9508 KB |
Output is correct |
55 |
Correct |
223 ms |
9704 KB |
Output is correct |
56 |
Correct |
99 ms |
9508 KB |
Output is correct |
57 |
Correct |
209 ms |
9704 KB |
Output is correct |
58 |
Correct |
116 ms |
9508 KB |
Output is correct |
59 |
Correct |
136 ms |
9704 KB |
Output is correct |
60 |
Correct |
29 ms |
9236 KB |
Output is correct |
61 |
Correct |
183 ms |
9704 KB |
Output is correct |
62 |
Correct |
179 ms |
9704 KB |
Output is correct |
63 |
Correct |
183 ms |
9704 KB |
Output is correct |
64 |
Correct |
176 ms |
9704 KB |
Output is correct |
65 |
Correct |
106 ms |
9236 KB |
Output is correct |
66 |
Correct |
123 ms |
9376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
9236 KB |
Output is correct |
2 |
Correct |
0 ms |
9236 KB |
Output is correct |
3 |
Correct |
0 ms |
9236 KB |
Output is correct |
4 |
Correct |
0 ms |
9236 KB |
Output is correct |
5 |
Correct |
0 ms |
9236 KB |
Output is correct |
6 |
Correct |
0 ms |
9236 KB |
Output is correct |
7 |
Correct |
0 ms |
9236 KB |
Output is correct |
8 |
Correct |
0 ms |
9236 KB |
Output is correct |
9 |
Correct |
0 ms |
9236 KB |
Output is correct |
10 |
Correct |
0 ms |
9236 KB |
Output is correct |
11 |
Correct |
0 ms |
9236 KB |
Output is correct |
12 |
Correct |
0 ms |
9236 KB |
Output is correct |
13 |
Correct |
0 ms |
9236 KB |
Output is correct |
14 |
Correct |
0 ms |
9236 KB |
Output is correct |
15 |
Correct |
0 ms |
9236 KB |
Output is correct |
16 |
Correct |
0 ms |
9236 KB |
Output is correct |
17 |
Correct |
0 ms |
9236 KB |
Output is correct |
18 |
Correct |
0 ms |
9236 KB |
Output is correct |
19 |
Correct |
0 ms |
9236 KB |
Output is correct |
20 |
Correct |
0 ms |
9236 KB |
Output is correct |
21 |
Correct |
0 ms |
9236 KB |
Output is correct |
22 |
Correct |
0 ms |
9236 KB |
Output is correct |
23 |
Correct |
0 ms |
9236 KB |
Output is correct |
24 |
Correct |
3 ms |
9236 KB |
Output is correct |
25 |
Correct |
6 ms |
9236 KB |
Output is correct |
26 |
Correct |
3 ms |
9236 KB |
Output is correct |
27 |
Correct |
6 ms |
9236 KB |
Output is correct |
28 |
Correct |
3 ms |
9236 KB |
Output is correct |
29 |
Correct |
6 ms |
9236 KB |
Output is correct |
30 |
Correct |
3 ms |
9236 KB |
Output is correct |
31 |
Correct |
3 ms |
9236 KB |
Output is correct |
32 |
Correct |
0 ms |
9236 KB |
Output is correct |
33 |
Correct |
3 ms |
9236 KB |
Output is correct |
34 |
Correct |
3 ms |
9236 KB |
Output is correct |
35 |
Correct |
6 ms |
9236 KB |
Output is correct |
36 |
Correct |
3 ms |
9236 KB |
Output is correct |
37 |
Correct |
39 ms |
9376 KB |
Output is correct |
38 |
Correct |
26 ms |
9376 KB |
Output is correct |
39 |
Correct |
73 ms |
9236 KB |
Output is correct |
40 |
Correct |
49 ms |
9376 KB |
Output is correct |
41 |
Correct |
123 ms |
9236 KB |
Output is correct |
42 |
Correct |
59 ms |
9376 KB |
Output is correct |
43 |
Correct |
69 ms |
9508 KB |
Output is correct |
44 |
Correct |
83 ms |
9508 KB |
Output is correct |
45 |
Correct |
93 ms |
9508 KB |
Output is correct |
46 |
Correct |
56 ms |
9236 KB |
Output is correct |
47 |
Correct |
69 ms |
9376 KB |
Output is correct |
48 |
Correct |
103 ms |
9508 KB |
Output is correct |
49 |
Correct |
86 ms |
9376 KB |
Output is correct |
50 |
Correct |
43 ms |
9376 KB |
Output is correct |
51 |
Correct |
9 ms |
9236 KB |
Output is correct |
52 |
Correct |
103 ms |
9508 KB |
Output is correct |
53 |
Correct |
69 ms |
9508 KB |
Output is correct |
54 |
Correct |
103 ms |
9508 KB |
Output is correct |
55 |
Correct |
223 ms |
9704 KB |
Output is correct |
56 |
Correct |
99 ms |
9508 KB |
Output is correct |
57 |
Correct |
209 ms |
9704 KB |
Output is correct |
58 |
Correct |
116 ms |
9508 KB |
Output is correct |
59 |
Correct |
136 ms |
9704 KB |
Output is correct |
60 |
Correct |
29 ms |
9236 KB |
Output is correct |
61 |
Correct |
183 ms |
9704 KB |
Output is correct |
62 |
Correct |
179 ms |
9704 KB |
Output is correct |
63 |
Correct |
183 ms |
9704 KB |
Output is correct |
64 |
Correct |
176 ms |
9704 KB |
Output is correct |
65 |
Correct |
106 ms |
9236 KB |
Output is correct |
66 |
Correct |
123 ms |
9376 KB |
Output is correct |
67 |
Correct |
199 ms |
9704 KB |
Output is correct |
68 |
Correct |
66 ms |
9236 KB |
Output is correct |
69 |
Correct |
639 ms |
10088 KB |
Output is correct |
70 |
Correct |
399 ms |
9704 KB |
Output is correct |
71 |
Correct |
333 ms |
9704 KB |
Output is correct |
72 |
Correct |
326 ms |
9236 KB |
Output is correct |
73 |
Correct |
359 ms |
9236 KB |
Output is correct |
74 |
Correct |
639 ms |
10088 KB |
Output is correct |
75 |
Correct |
486 ms |
10088 KB |
Output is correct |
76 |
Correct |
719 ms |
10088 KB |
Output is correct |
77 |
Correct |
666 ms |
10088 KB |
Output is correct |