#include <bits/stdc++.h>
using namespace std;
const int N = 505, MOD = 1e9 + 7;
int dp[N * N], cnt[N * N], a[N], n, tmp[N * N], h2[N * N], t2[N * N];
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("IZhO17_bootfall.INP", "r", stdin);
// freopen("IZhO17_bootfall.OUT", "w", stdout);
cin >> n;
int s = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
s += a[i];
}
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = s; j >= 0; --j) if (a[i] <= j) {
dp[j] += dp[j - a[i]];
}
}
h2[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = s; j >= 0; --j) if (a[i] <= j) {
(h2[j] += h2[j - a[i]]) %= MOD;
}
}
if (s & 1) {
cout << 0 << endl;
return 0;
}
if (dp[s / 2] == 0 && h2[s / 2] == 0) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= s; ++j) tmp[j] = dp[j];
tmp[a[i]]--;
for (int j = a[i] + 1; j <= s; ++j)
tmp[j] -= tmp[j - a[i]];
for (int j = 0; j <= s; ++j) t2[j] = h2[j];
t2[a[i]] = (t2[a[i]] - 1 + MOD) % MOD;
for (int j = a[i] + 1; j <= s; ++j)
t2[j] = (t2[j] - t2[j - a[i]] + MOD) % MOD;
s -= a[i];
// if (i == 3) cerr << "#" << (s - 155) / 2 << endl;
for (int j = 0; j <= s / 2; ++j) if (tmp[j] != 0 && t2[j] != 0) {
// if (s - 2 * j == 155) cerr << i << endl;
cnt[s - 2 * j]++;
}
s += a[i];
}
vector <int> res; res.clear();
for (int i = 1; i <= s; ++i) if (cnt[i] == n)
res.push_back(i);
cout << res.size() << endl;
for (int v : res) cout << v << ' ';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
544 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
7 ms |
512 KB |
Output is correct |
28 |
Correct |
7 ms |
640 KB |
Output is correct |
29 |
Correct |
8 ms |
512 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
4 ms |
512 KB |
Output is correct |
33 |
Correct |
8 ms |
512 KB |
Output is correct |
34 |
Correct |
8 ms |
512 KB |
Output is correct |
35 |
Correct |
8 ms |
640 KB |
Output is correct |
36 |
Correct |
4 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
544 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
7 ms |
512 KB |
Output is correct |
28 |
Correct |
7 ms |
640 KB |
Output is correct |
29 |
Correct |
8 ms |
512 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
4 ms |
512 KB |
Output is correct |
33 |
Correct |
8 ms |
512 KB |
Output is correct |
34 |
Correct |
8 ms |
512 KB |
Output is correct |
35 |
Correct |
8 ms |
640 KB |
Output is correct |
36 |
Correct |
4 ms |
512 KB |
Output is correct |
37 |
Correct |
28 ms |
888 KB |
Output is correct |
38 |
Correct |
30 ms |
896 KB |
Output is correct |
39 |
Correct |
106 ms |
1528 KB |
Output is correct |
40 |
Correct |
63 ms |
1272 KB |
Output is correct |
41 |
Correct |
136 ms |
1784 KB |
Output is correct |
42 |
Correct |
55 ms |
1144 KB |
Output is correct |
43 |
Correct |
97 ms |
1784 KB |
Output is correct |
44 |
Correct |
103 ms |
1912 KB |
Output is correct |
45 |
Correct |
103 ms |
1912 KB |
Output is correct |
46 |
Correct |
61 ms |
1016 KB |
Output is correct |
47 |
Correct |
59 ms |
1272 KB |
Output is correct |
48 |
Correct |
113 ms |
1912 KB |
Output is correct |
49 |
Correct |
110 ms |
1624 KB |
Output is correct |
50 |
Correct |
60 ms |
1276 KB |
Output is correct |
51 |
Correct |
25 ms |
640 KB |
Output is correct |
52 |
Correct |
138 ms |
2172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
544 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
7 ms |
512 KB |
Output is correct |
28 |
Correct |
7 ms |
640 KB |
Output is correct |
29 |
Correct |
8 ms |
512 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
4 ms |
512 KB |
Output is correct |
33 |
Correct |
8 ms |
512 KB |
Output is correct |
34 |
Correct |
8 ms |
512 KB |
Output is correct |
35 |
Correct |
8 ms |
640 KB |
Output is correct |
36 |
Correct |
4 ms |
512 KB |
Output is correct |
37 |
Correct |
28 ms |
888 KB |
Output is correct |
38 |
Correct |
30 ms |
896 KB |
Output is correct |
39 |
Correct |
106 ms |
1528 KB |
Output is correct |
40 |
Correct |
63 ms |
1272 KB |
Output is correct |
41 |
Correct |
136 ms |
1784 KB |
Output is correct |
42 |
Correct |
55 ms |
1144 KB |
Output is correct |
43 |
Correct |
97 ms |
1784 KB |
Output is correct |
44 |
Correct |
103 ms |
1912 KB |
Output is correct |
45 |
Correct |
103 ms |
1912 KB |
Output is correct |
46 |
Correct |
61 ms |
1016 KB |
Output is correct |
47 |
Correct |
59 ms |
1272 KB |
Output is correct |
48 |
Correct |
113 ms |
1912 KB |
Output is correct |
49 |
Correct |
110 ms |
1624 KB |
Output is correct |
50 |
Correct |
60 ms |
1276 KB |
Output is correct |
51 |
Correct |
25 ms |
640 KB |
Output is correct |
52 |
Correct |
138 ms |
2172 KB |
Output is correct |
53 |
Correct |
98 ms |
1656 KB |
Output is correct |
54 |
Correct |
138 ms |
1784 KB |
Output is correct |
55 |
Correct |
284 ms |
3272 KB |
Output is correct |
56 |
Correct |
122 ms |
1912 KB |
Output is correct |
57 |
Correct |
294 ms |
3320 KB |
Output is correct |
58 |
Correct |
159 ms |
2040 KB |
Output is correct |
59 |
Correct |
191 ms |
2296 KB |
Output is correct |
60 |
Correct |
65 ms |
780 KB |
Output is correct |
61 |
Correct |
215 ms |
2620 KB |
Output is correct |
62 |
Correct |
218 ms |
2800 KB |
Output is correct |
63 |
Correct |
235 ms |
3064 KB |
Output is correct |
64 |
Correct |
227 ms |
2936 KB |
Output is correct |
65 |
Correct |
110 ms |
1400 KB |
Output is correct |
66 |
Correct |
115 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
544 KB |
Output is correct |
25 |
Correct |
7 ms |
640 KB |
Output is correct |
26 |
Correct |
8 ms |
640 KB |
Output is correct |
27 |
Correct |
7 ms |
512 KB |
Output is correct |
28 |
Correct |
7 ms |
640 KB |
Output is correct |
29 |
Correct |
8 ms |
512 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
512 KB |
Output is correct |
32 |
Correct |
4 ms |
512 KB |
Output is correct |
33 |
Correct |
8 ms |
512 KB |
Output is correct |
34 |
Correct |
8 ms |
512 KB |
Output is correct |
35 |
Correct |
8 ms |
640 KB |
Output is correct |
36 |
Correct |
4 ms |
512 KB |
Output is correct |
37 |
Correct |
28 ms |
888 KB |
Output is correct |
38 |
Correct |
30 ms |
896 KB |
Output is correct |
39 |
Correct |
106 ms |
1528 KB |
Output is correct |
40 |
Correct |
63 ms |
1272 KB |
Output is correct |
41 |
Correct |
136 ms |
1784 KB |
Output is correct |
42 |
Correct |
55 ms |
1144 KB |
Output is correct |
43 |
Correct |
97 ms |
1784 KB |
Output is correct |
44 |
Correct |
103 ms |
1912 KB |
Output is correct |
45 |
Correct |
103 ms |
1912 KB |
Output is correct |
46 |
Correct |
61 ms |
1016 KB |
Output is correct |
47 |
Correct |
59 ms |
1272 KB |
Output is correct |
48 |
Correct |
113 ms |
1912 KB |
Output is correct |
49 |
Correct |
110 ms |
1624 KB |
Output is correct |
50 |
Correct |
60 ms |
1276 KB |
Output is correct |
51 |
Correct |
25 ms |
640 KB |
Output is correct |
52 |
Correct |
138 ms |
2172 KB |
Output is correct |
53 |
Correct |
98 ms |
1656 KB |
Output is correct |
54 |
Correct |
138 ms |
1784 KB |
Output is correct |
55 |
Correct |
284 ms |
3272 KB |
Output is correct |
56 |
Correct |
122 ms |
1912 KB |
Output is correct |
57 |
Correct |
294 ms |
3320 KB |
Output is correct |
58 |
Correct |
159 ms |
2040 KB |
Output is correct |
59 |
Correct |
191 ms |
2296 KB |
Output is correct |
60 |
Correct |
65 ms |
780 KB |
Output is correct |
61 |
Correct |
215 ms |
2620 KB |
Output is correct |
62 |
Correct |
218 ms |
2800 KB |
Output is correct |
63 |
Correct |
235 ms |
3064 KB |
Output is correct |
64 |
Correct |
227 ms |
2936 KB |
Output is correct |
65 |
Correct |
110 ms |
1400 KB |
Output is correct |
66 |
Correct |
115 ms |
1528 KB |
Output is correct |
67 |
Correct |
233 ms |
2552 KB |
Output is correct |
68 |
Correct |
184 ms |
1400 KB |
Output is correct |
69 |
Correct |
755 ms |
5748 KB |
Output is correct |
70 |
Correct |
450 ms |
3704 KB |
Output is correct |
71 |
Correct |
440 ms |
3704 KB |
Output is correct |
72 |
Correct |
443 ms |
2936 KB |
Output is correct |
73 |
Correct |
434 ms |
2792 KB |
Output is correct |
74 |
Correct |
801 ms |
6004 KB |
Output is correct |
75 |
Correct |
628 ms |
4852 KB |
Output is correct |
76 |
Correct |
878 ms |
6388 KB |
Output is correct |
77 |
Correct |
852 ms |
6452 KB |
Output is correct |