#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 5e2 + 1, maxm = 3e5 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
ll n, sum;
unsigned ll a[maxn], dp[maxm], cnt[maxm], ans[maxm];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for(int j = maxm - 1; j >= a[i]; j--)
dp[j] += dp[j - a[i]];
sum += a[i];
}
if (sum % 2 != 0 || dp[sum / 2] == 0){
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i){
for (int j = a[i]; j <= maxm - 1; ++j){
dp[j] -= dp[j - a[i]];
}
for (int j = 0; j <= maxm - 1; ++j){
if (dp[j] > 0){
int f = j, s = sum - a[i] - j;
int rz = abs(f - s);
cnt[rz] = 1;
}
}
for (int j = 0; j <= maxm - 1; ++j){
if (cnt[j] > 0){
ans[j]++;
}
cnt[j] = 0;
}
for (int j = maxm - 1; j >= a[i]; --j){
dp[j] += dp[j - a[i]];
}
}
vector<int> v;
for (int i = 1; i <= maxm - 1; ++i){
if (ans[i] == n){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:25:33: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
25 | for(int j = maxm - 1; j >= a[i]; j--)
| ~~^~~~~~~
bootfall.cpp:50:34: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
50 | for (int j = maxm - 1; j >= a[i]; --j){
| ~~^~~~~~~
bootfall.cpp:56:20: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
56 | if (ans[i] == n){
| ~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
10 |
Correct |
34 ms |
4976 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
36 ms |
4940 KB |
Output is correct |
13 |
Correct |
32 ms |
4972 KB |
Output is correct |
14 |
Correct |
32 ms |
4952 KB |
Output is correct |
15 |
Correct |
36 ms |
4984 KB |
Output is correct |
16 |
Correct |
40 ms |
4976 KB |
Output is correct |
17 |
Correct |
22 ms |
4880 KB |
Output is correct |
18 |
Correct |
30 ms |
4976 KB |
Output is correct |
19 |
Correct |
34 ms |
4940 KB |
Output is correct |
20 |
Correct |
36 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
10 |
Correct |
34 ms |
4976 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
36 ms |
4940 KB |
Output is correct |
13 |
Correct |
32 ms |
4972 KB |
Output is correct |
14 |
Correct |
32 ms |
4952 KB |
Output is correct |
15 |
Correct |
36 ms |
4984 KB |
Output is correct |
16 |
Correct |
40 ms |
4976 KB |
Output is correct |
17 |
Correct |
22 ms |
4880 KB |
Output is correct |
18 |
Correct |
30 ms |
4976 KB |
Output is correct |
19 |
Correct |
34 ms |
4940 KB |
Output is correct |
20 |
Correct |
36 ms |
4940 KB |
Output is correct |
21 |
Correct |
70 ms |
5060 KB |
Output is correct |
22 |
Correct |
80 ms |
5000 KB |
Output is correct |
23 |
Correct |
74 ms |
5036 KB |
Output is correct |
24 |
Correct |
97 ms |
4948 KB |
Output is correct |
25 |
Correct |
103 ms |
5056 KB |
Output is correct |
26 |
Correct |
106 ms |
5044 KB |
Output is correct |
27 |
Correct |
103 ms |
5068 KB |
Output is correct |
28 |
Correct |
106 ms |
5068 KB |
Output is correct |
29 |
Correct |
105 ms |
5052 KB |
Output is correct |
30 |
Correct |
107 ms |
5012 KB |
Output is correct |
31 |
Correct |
102 ms |
5060 KB |
Output is correct |
32 |
Correct |
104 ms |
5012 KB |
Output is correct |
33 |
Correct |
114 ms |
5052 KB |
Output is correct |
34 |
Correct |
103 ms |
4948 KB |
Output is correct |
35 |
Correct |
102 ms |
5052 KB |
Output is correct |
36 |
Correct |
104 ms |
5060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
10 |
Correct |
34 ms |
4976 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
36 ms |
4940 KB |
Output is correct |
13 |
Correct |
32 ms |
4972 KB |
Output is correct |
14 |
Correct |
32 ms |
4952 KB |
Output is correct |
15 |
Correct |
36 ms |
4984 KB |
Output is correct |
16 |
Correct |
40 ms |
4976 KB |
Output is correct |
17 |
Correct |
22 ms |
4880 KB |
Output is correct |
18 |
Correct |
30 ms |
4976 KB |
Output is correct |
19 |
Correct |
34 ms |
4940 KB |
Output is correct |
20 |
Correct |
36 ms |
4940 KB |
Output is correct |
21 |
Correct |
70 ms |
5060 KB |
Output is correct |
22 |
Correct |
80 ms |
5000 KB |
Output is correct |
23 |
Correct |
74 ms |
5036 KB |
Output is correct |
24 |
Correct |
97 ms |
4948 KB |
Output is correct |
25 |
Correct |
103 ms |
5056 KB |
Output is correct |
26 |
Correct |
106 ms |
5044 KB |
Output is correct |
27 |
Correct |
103 ms |
5068 KB |
Output is correct |
28 |
Correct |
106 ms |
5068 KB |
Output is correct |
29 |
Correct |
105 ms |
5052 KB |
Output is correct |
30 |
Correct |
107 ms |
5012 KB |
Output is correct |
31 |
Correct |
102 ms |
5060 KB |
Output is correct |
32 |
Correct |
104 ms |
5012 KB |
Output is correct |
33 |
Correct |
114 ms |
5052 KB |
Output is correct |
34 |
Correct |
103 ms |
4948 KB |
Output is correct |
35 |
Correct |
102 ms |
5052 KB |
Output is correct |
36 |
Correct |
104 ms |
5060 KB |
Output is correct |
37 |
Correct |
224 ms |
5256 KB |
Output is correct |
38 |
Correct |
201 ms |
5188 KB |
Output is correct |
39 |
Correct |
265 ms |
5456 KB |
Output is correct |
40 |
Correct |
296 ms |
5444 KB |
Output is correct |
41 |
Correct |
280 ms |
5576 KB |
Output is correct |
42 |
Correct |
251 ms |
5340 KB |
Output is correct |
43 |
Correct |
264 ms |
5788 KB |
Output is correct |
44 |
Correct |
257 ms |
5796 KB |
Output is correct |
45 |
Correct |
261 ms |
5700 KB |
Output is correct |
46 |
Correct |
285 ms |
5224 KB |
Output is correct |
47 |
Correct |
256 ms |
5360 KB |
Output is correct |
48 |
Correct |
267 ms |
5712 KB |
Output is correct |
49 |
Correct |
256 ms |
5456 KB |
Output is correct |
50 |
Correct |
254 ms |
5456 KB |
Output is correct |
51 |
Correct |
52 ms |
2636 KB |
Output is correct |
52 |
Correct |
276 ms |
5840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
10 |
Correct |
34 ms |
4976 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
36 ms |
4940 KB |
Output is correct |
13 |
Correct |
32 ms |
4972 KB |
Output is correct |
14 |
Correct |
32 ms |
4952 KB |
Output is correct |
15 |
Correct |
36 ms |
4984 KB |
Output is correct |
16 |
Correct |
40 ms |
4976 KB |
Output is correct |
17 |
Correct |
22 ms |
4880 KB |
Output is correct |
18 |
Correct |
30 ms |
4976 KB |
Output is correct |
19 |
Correct |
34 ms |
4940 KB |
Output is correct |
20 |
Correct |
36 ms |
4940 KB |
Output is correct |
21 |
Correct |
70 ms |
5060 KB |
Output is correct |
22 |
Correct |
80 ms |
5000 KB |
Output is correct |
23 |
Correct |
74 ms |
5036 KB |
Output is correct |
24 |
Correct |
97 ms |
4948 KB |
Output is correct |
25 |
Correct |
103 ms |
5056 KB |
Output is correct |
26 |
Correct |
106 ms |
5044 KB |
Output is correct |
27 |
Correct |
103 ms |
5068 KB |
Output is correct |
28 |
Correct |
106 ms |
5068 KB |
Output is correct |
29 |
Correct |
105 ms |
5052 KB |
Output is correct |
30 |
Correct |
107 ms |
5012 KB |
Output is correct |
31 |
Correct |
102 ms |
5060 KB |
Output is correct |
32 |
Correct |
104 ms |
5012 KB |
Output is correct |
33 |
Correct |
114 ms |
5052 KB |
Output is correct |
34 |
Correct |
103 ms |
4948 KB |
Output is correct |
35 |
Correct |
102 ms |
5052 KB |
Output is correct |
36 |
Correct |
104 ms |
5060 KB |
Output is correct |
37 |
Correct |
224 ms |
5256 KB |
Output is correct |
38 |
Correct |
201 ms |
5188 KB |
Output is correct |
39 |
Correct |
265 ms |
5456 KB |
Output is correct |
40 |
Correct |
296 ms |
5444 KB |
Output is correct |
41 |
Correct |
280 ms |
5576 KB |
Output is correct |
42 |
Correct |
251 ms |
5340 KB |
Output is correct |
43 |
Correct |
264 ms |
5788 KB |
Output is correct |
44 |
Correct |
257 ms |
5796 KB |
Output is correct |
45 |
Correct |
261 ms |
5700 KB |
Output is correct |
46 |
Correct |
285 ms |
5224 KB |
Output is correct |
47 |
Correct |
256 ms |
5360 KB |
Output is correct |
48 |
Correct |
267 ms |
5712 KB |
Output is correct |
49 |
Correct |
256 ms |
5456 KB |
Output is correct |
50 |
Correct |
254 ms |
5456 KB |
Output is correct |
51 |
Correct |
52 ms |
2636 KB |
Output is correct |
52 |
Correct |
276 ms |
5840 KB |
Output is correct |
53 |
Correct |
305 ms |
5576 KB |
Output is correct |
54 |
Correct |
363 ms |
5828 KB |
Output is correct |
55 |
Correct |
375 ms |
6348 KB |
Output is correct |
56 |
Correct |
354 ms |
5800 KB |
Output is correct |
57 |
Correct |
371 ms |
6464 KB |
Output is correct |
58 |
Correct |
370 ms |
5836 KB |
Output is correct |
59 |
Correct |
360 ms |
6208 KB |
Output is correct |
60 |
Correct |
78 ms |
2636 KB |
Output is correct |
61 |
Correct |
381 ms |
6076 KB |
Output is correct |
62 |
Correct |
370 ms |
6208 KB |
Output is correct |
63 |
Correct |
342 ms |
6300 KB |
Output is correct |
64 |
Correct |
343 ms |
6348 KB |
Output is correct |
65 |
Correct |
344 ms |
5352 KB |
Output is correct |
66 |
Correct |
312 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4940 KB |
Output is correct |
2 |
Correct |
10 ms |
4972 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
8 ms |
4940 KB |
Output is correct |
5 |
Correct |
16 ms |
4952 KB |
Output is correct |
6 |
Correct |
12 ms |
4940 KB |
Output is correct |
7 |
Correct |
10 ms |
4992 KB |
Output is correct |
8 |
Correct |
15 ms |
5012 KB |
Output is correct |
9 |
Correct |
14 ms |
4952 KB |
Output is correct |
10 |
Correct |
34 ms |
4976 KB |
Output is correct |
11 |
Correct |
36 ms |
4988 KB |
Output is correct |
12 |
Correct |
36 ms |
4940 KB |
Output is correct |
13 |
Correct |
32 ms |
4972 KB |
Output is correct |
14 |
Correct |
32 ms |
4952 KB |
Output is correct |
15 |
Correct |
36 ms |
4984 KB |
Output is correct |
16 |
Correct |
40 ms |
4976 KB |
Output is correct |
17 |
Correct |
22 ms |
4880 KB |
Output is correct |
18 |
Correct |
30 ms |
4976 KB |
Output is correct |
19 |
Correct |
34 ms |
4940 KB |
Output is correct |
20 |
Correct |
36 ms |
4940 KB |
Output is correct |
21 |
Correct |
70 ms |
5060 KB |
Output is correct |
22 |
Correct |
80 ms |
5000 KB |
Output is correct |
23 |
Correct |
74 ms |
5036 KB |
Output is correct |
24 |
Correct |
97 ms |
4948 KB |
Output is correct |
25 |
Correct |
103 ms |
5056 KB |
Output is correct |
26 |
Correct |
106 ms |
5044 KB |
Output is correct |
27 |
Correct |
103 ms |
5068 KB |
Output is correct |
28 |
Correct |
106 ms |
5068 KB |
Output is correct |
29 |
Correct |
105 ms |
5052 KB |
Output is correct |
30 |
Correct |
107 ms |
5012 KB |
Output is correct |
31 |
Correct |
102 ms |
5060 KB |
Output is correct |
32 |
Correct |
104 ms |
5012 KB |
Output is correct |
33 |
Correct |
114 ms |
5052 KB |
Output is correct |
34 |
Correct |
103 ms |
4948 KB |
Output is correct |
35 |
Correct |
102 ms |
5052 KB |
Output is correct |
36 |
Correct |
104 ms |
5060 KB |
Output is correct |
37 |
Correct |
224 ms |
5256 KB |
Output is correct |
38 |
Correct |
201 ms |
5188 KB |
Output is correct |
39 |
Correct |
265 ms |
5456 KB |
Output is correct |
40 |
Correct |
296 ms |
5444 KB |
Output is correct |
41 |
Correct |
280 ms |
5576 KB |
Output is correct |
42 |
Correct |
251 ms |
5340 KB |
Output is correct |
43 |
Correct |
264 ms |
5788 KB |
Output is correct |
44 |
Correct |
257 ms |
5796 KB |
Output is correct |
45 |
Correct |
261 ms |
5700 KB |
Output is correct |
46 |
Correct |
285 ms |
5224 KB |
Output is correct |
47 |
Correct |
256 ms |
5360 KB |
Output is correct |
48 |
Correct |
267 ms |
5712 KB |
Output is correct |
49 |
Correct |
256 ms |
5456 KB |
Output is correct |
50 |
Correct |
254 ms |
5456 KB |
Output is correct |
51 |
Correct |
52 ms |
2636 KB |
Output is correct |
52 |
Correct |
276 ms |
5840 KB |
Output is correct |
53 |
Correct |
305 ms |
5576 KB |
Output is correct |
54 |
Correct |
363 ms |
5828 KB |
Output is correct |
55 |
Correct |
375 ms |
6348 KB |
Output is correct |
56 |
Correct |
354 ms |
5800 KB |
Output is correct |
57 |
Correct |
371 ms |
6464 KB |
Output is correct |
58 |
Correct |
370 ms |
5836 KB |
Output is correct |
59 |
Correct |
360 ms |
6208 KB |
Output is correct |
60 |
Correct |
78 ms |
2636 KB |
Output is correct |
61 |
Correct |
381 ms |
6076 KB |
Output is correct |
62 |
Correct |
370 ms |
6208 KB |
Output is correct |
63 |
Correct |
342 ms |
6300 KB |
Output is correct |
64 |
Correct |
343 ms |
6348 KB |
Output is correct |
65 |
Correct |
344 ms |
5352 KB |
Output is correct |
66 |
Correct |
312 ms |
5452 KB |
Output is correct |
67 |
Correct |
439 ms |
6204 KB |
Output is correct |
68 |
Correct |
109 ms |
2636 KB |
Output is correct |
69 |
Correct |
573 ms |
7880 KB |
Output is correct |
70 |
Correct |
528 ms |
6716 KB |
Output is correct |
71 |
Correct |
555 ms |
6584 KB |
Output is correct |
72 |
Correct |
551 ms |
5964 KB |
Output is correct |
73 |
Correct |
560 ms |
5952 KB |
Output is correct |
74 |
Correct |
563 ms |
7868 KB |
Output is correct |
75 |
Correct |
560 ms |
7352 KB |
Output is correct |
76 |
Correct |
570 ms |
8008 KB |
Output is correct |
77 |
Correct |
567 ms |
8124 KB |
Output is correct |