#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 500+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int a[N] , u[N] , ans[N*N];
int dp[N*N];
void solve() {
int n;
cin >> n;
ll sum = 0;
int cnt[2];
cnt[0]=cnt[1]=0;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
sum += a[i];
cnt[a[i]%2] = 1;
}
if(sum % 2 || cnt[0] == cnt[1]) {
cout << "0";
return;
}
dp[0] = 1;
for(int i = 1; i <= n; i ++) {
for(int j = sum; j >= 0; j --) {
if(j + a[i] <= sum) {
dp[j+a[i]] += dp[j];
}
}
}
if(!dp[sum/2]) {
cout << "0";
return;
}
int f = 0;
for(int i = 1; i <= n; i ++) {
if(u[a[i]]) continue;
u[a[i]] = 1;
f ++;
for(int j = 0; j < sum; j ++) {
if(j + a[i] <= sum) {
dp[j+a[i]] -= dp[j];
}
}
sum -= a[i];
// cout << a[i] << ": \n";
for(int i = 2 - cnt[1]; i <= sum; i += 2) {
if(dp[(sum+i) / 2]) {
// cout << " " << i << '\n';
ans[i] ++;
}
}
sum += a[i];
for(int j = sum; j >= 0; j --) {
if(j + a[i] <= sum) {
dp[j+a[i]] += dp[j];
}
}
}
vector<int> v;
for(int i = 1; i < N*N; i ++) {
if(ans[i] == f) {
v.push_back(i);
}
}
cout << v.size() << '\n';
for(auto to: v) {
cout << to << ' ';
}
}
/*
1 2 1 2 2
*/
main() {
ios;
int tt = 1;
//cin >> tt;
while(tt --) {
solve();
}
return 0;
}
Compilation message
bootfall.cpp:92:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
92 | main() {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
3 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
3 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
3 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
3 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
620 KB |
Output is correct |
38 |
Correct |
9 ms |
620 KB |
Output is correct |
39 |
Correct |
18 ms |
876 KB |
Output is correct |
40 |
Correct |
26 ms |
876 KB |
Output is correct |
41 |
Correct |
21 ms |
876 KB |
Output is correct |
42 |
Correct |
18 ms |
748 KB |
Output is correct |
43 |
Correct |
21 ms |
1132 KB |
Output is correct |
44 |
Correct |
22 ms |
1132 KB |
Output is correct |
45 |
Correct |
22 ms |
1132 KB |
Output is correct |
46 |
Correct |
22 ms |
748 KB |
Output is correct |
47 |
Correct |
19 ms |
876 KB |
Output is correct |
48 |
Correct |
19 ms |
1132 KB |
Output is correct |
49 |
Correct |
18 ms |
876 KB |
Output is correct |
50 |
Correct |
20 ms |
876 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
28 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
3 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
3 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
620 KB |
Output is correct |
38 |
Correct |
9 ms |
620 KB |
Output is correct |
39 |
Correct |
18 ms |
876 KB |
Output is correct |
40 |
Correct |
26 ms |
876 KB |
Output is correct |
41 |
Correct |
21 ms |
876 KB |
Output is correct |
42 |
Correct |
18 ms |
748 KB |
Output is correct |
43 |
Correct |
21 ms |
1132 KB |
Output is correct |
44 |
Correct |
22 ms |
1132 KB |
Output is correct |
45 |
Correct |
22 ms |
1132 KB |
Output is correct |
46 |
Correct |
22 ms |
748 KB |
Output is correct |
47 |
Correct |
19 ms |
876 KB |
Output is correct |
48 |
Correct |
19 ms |
1132 KB |
Output is correct |
49 |
Correct |
18 ms |
876 KB |
Output is correct |
50 |
Correct |
20 ms |
876 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
28 ms |
1388 KB |
Output is correct |
53 |
Correct |
29 ms |
1004 KB |
Output is correct |
54 |
Correct |
38 ms |
1132 KB |
Output is correct |
55 |
Correct |
48 ms |
1904 KB |
Output is correct |
56 |
Correct |
36 ms |
1132 KB |
Output is correct |
57 |
Correct |
51 ms |
1904 KB |
Output is correct |
58 |
Correct |
49 ms |
1260 KB |
Output is correct |
59 |
Correct |
47 ms |
1392 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
52 ms |
1520 KB |
Output is correct |
62 |
Correct |
47 ms |
1648 KB |
Output is correct |
63 |
Correct |
48 ms |
1776 KB |
Output is correct |
64 |
Correct |
45 ms |
1904 KB |
Output is correct |
65 |
Correct |
20 ms |
748 KB |
Output is correct |
66 |
Correct |
23 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
3 ms |
364 KB |
Output is correct |
24 |
Correct |
3 ms |
364 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
3 ms |
492 KB |
Output is correct |
27 |
Correct |
3 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
492 KB |
Output is correct |
32 |
Correct |
3 ms |
492 KB |
Output is correct |
33 |
Correct |
3 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
3 ms |
364 KB |
Output is correct |
37 |
Correct |
9 ms |
620 KB |
Output is correct |
38 |
Correct |
9 ms |
620 KB |
Output is correct |
39 |
Correct |
18 ms |
876 KB |
Output is correct |
40 |
Correct |
26 ms |
876 KB |
Output is correct |
41 |
Correct |
21 ms |
876 KB |
Output is correct |
42 |
Correct |
18 ms |
748 KB |
Output is correct |
43 |
Correct |
21 ms |
1132 KB |
Output is correct |
44 |
Correct |
22 ms |
1132 KB |
Output is correct |
45 |
Correct |
22 ms |
1132 KB |
Output is correct |
46 |
Correct |
22 ms |
748 KB |
Output is correct |
47 |
Correct |
19 ms |
876 KB |
Output is correct |
48 |
Correct |
19 ms |
1132 KB |
Output is correct |
49 |
Correct |
18 ms |
876 KB |
Output is correct |
50 |
Correct |
20 ms |
876 KB |
Output is correct |
51 |
Correct |
1 ms |
364 KB |
Output is correct |
52 |
Correct |
28 ms |
1388 KB |
Output is correct |
53 |
Correct |
29 ms |
1004 KB |
Output is correct |
54 |
Correct |
38 ms |
1132 KB |
Output is correct |
55 |
Correct |
48 ms |
1904 KB |
Output is correct |
56 |
Correct |
36 ms |
1132 KB |
Output is correct |
57 |
Correct |
51 ms |
1904 KB |
Output is correct |
58 |
Correct |
49 ms |
1260 KB |
Output is correct |
59 |
Correct |
47 ms |
1392 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
52 ms |
1520 KB |
Output is correct |
62 |
Correct |
47 ms |
1648 KB |
Output is correct |
63 |
Correct |
48 ms |
1776 KB |
Output is correct |
64 |
Correct |
45 ms |
1904 KB |
Output is correct |
65 |
Correct |
20 ms |
748 KB |
Output is correct |
66 |
Correct |
23 ms |
876 KB |
Output is correct |
67 |
Correct |
71 ms |
1648 KB |
Output is correct |
68 |
Correct |
61 ms |
880 KB |
Output is correct |
69 |
Correct |
125 ms |
3180 KB |
Output is correct |
70 |
Correct |
138 ms |
2160 KB |
Output is correct |
71 |
Correct |
137 ms |
2160 KB |
Output is correct |
72 |
Correct |
1 ms |
364 KB |
Output is correct |
73 |
Correct |
1 ms |
364 KB |
Output is correct |
74 |
Correct |
144 ms |
3436 KB |
Output is correct |
75 |
Correct |
146 ms |
2796 KB |
Output is correct |
76 |
Correct |
137 ms |
3564 KB |
Output is correct |
77 |
Correct |
139 ms |
3584 KB |
Output is correct |