// DNC DP
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e6 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, k, a[N];
int dp[500 * 500 + 5], cnt[500 * 500 + 5];
vector<int> res;
void process() {
cin >> n;
int sum = 0;
foru(i, 1, n) {
cin >> a[i];
sum += a[i];
}
dp[0] = 1;
foru(i, 1, n) {
ford(j, sum - a[i], 0) {
dp[j + a[i]] += dp[j];
}
}
if ((sum & 1) || !dp[(sum >> 1)]) {
cout << 0 << '\n';
return;
}
foru(i, 1, n) {
int x = sum - a[i];
foru(j, 0, sum - a[i]) {
dp[j + a[i]] -= dp[j];
}
foru(j, (x + 1) >> 1, x) {
cnt[(j << 1) - x] += !!dp[j];
}
ford(j, sum - a[i], 0) {
dp[j + a[i]] += dp[j];
}
}
foru(i, 0, sum) if (cnt[i] == n) res.pb(i);
cout << res.size() << '\n';
for (auto x : res) cout << x << ' ';
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
3 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2512 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
3 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2512 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
8 ms |
2652 KB |
Output is correct |
38 |
Correct |
8 ms |
2512 KB |
Output is correct |
39 |
Correct |
29 ms |
2652 KB |
Output is correct |
40 |
Correct |
18 ms |
2804 KB |
Output is correct |
41 |
Correct |
42 ms |
2672 KB |
Output is correct |
42 |
Correct |
19 ms |
2652 KB |
Output is correct |
43 |
Correct |
27 ms |
2952 KB |
Output is correct |
44 |
Correct |
27 ms |
2908 KB |
Output is correct |
45 |
Correct |
28 ms |
2908 KB |
Output is correct |
46 |
Correct |
16 ms |
2396 KB |
Output is correct |
47 |
Correct |
17 ms |
2652 KB |
Output is correct |
48 |
Correct |
30 ms |
2908 KB |
Output is correct |
49 |
Correct |
33 ms |
3000 KB |
Output is correct |
50 |
Correct |
20 ms |
2652 KB |
Output is correct |
51 |
Correct |
4 ms |
2516 KB |
Output is correct |
52 |
Correct |
37 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
3 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2512 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
8 ms |
2652 KB |
Output is correct |
38 |
Correct |
8 ms |
2512 KB |
Output is correct |
39 |
Correct |
29 ms |
2652 KB |
Output is correct |
40 |
Correct |
18 ms |
2804 KB |
Output is correct |
41 |
Correct |
42 ms |
2672 KB |
Output is correct |
42 |
Correct |
19 ms |
2652 KB |
Output is correct |
43 |
Correct |
27 ms |
2952 KB |
Output is correct |
44 |
Correct |
27 ms |
2908 KB |
Output is correct |
45 |
Correct |
28 ms |
2908 KB |
Output is correct |
46 |
Correct |
16 ms |
2396 KB |
Output is correct |
47 |
Correct |
17 ms |
2652 KB |
Output is correct |
48 |
Correct |
30 ms |
2908 KB |
Output is correct |
49 |
Correct |
33 ms |
3000 KB |
Output is correct |
50 |
Correct |
20 ms |
2652 KB |
Output is correct |
51 |
Correct |
4 ms |
2516 KB |
Output is correct |
52 |
Correct |
37 ms |
2924 KB |
Output is correct |
53 |
Correct |
27 ms |
2908 KB |
Output is correct |
54 |
Correct |
38 ms |
2940 KB |
Output is correct |
55 |
Correct |
74 ms |
3076 KB |
Output is correct |
56 |
Correct |
33 ms |
2900 KB |
Output is correct |
57 |
Correct |
79 ms |
3288 KB |
Output is correct |
58 |
Correct |
41 ms |
2900 KB |
Output is correct |
59 |
Correct |
51 ms |
3076 KB |
Output is correct |
60 |
Correct |
10 ms |
2396 KB |
Output is correct |
61 |
Correct |
62 ms |
3060 KB |
Output is correct |
62 |
Correct |
65 ms |
3284 KB |
Output is correct |
63 |
Correct |
64 ms |
3088 KB |
Output is correct |
64 |
Correct |
61 ms |
3540 KB |
Output is correct |
65 |
Correct |
28 ms |
2652 KB |
Output is correct |
66 |
Correct |
31 ms |
2684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
0 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2508 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2512 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2396 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
2 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
3 ms |
2392 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2512 KB |
Output is correct |
32 |
Correct |
2 ms |
2396 KB |
Output is correct |
33 |
Correct |
2 ms |
2396 KB |
Output is correct |
34 |
Correct |
2 ms |
2396 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
8 ms |
2652 KB |
Output is correct |
38 |
Correct |
8 ms |
2512 KB |
Output is correct |
39 |
Correct |
29 ms |
2652 KB |
Output is correct |
40 |
Correct |
18 ms |
2804 KB |
Output is correct |
41 |
Correct |
42 ms |
2672 KB |
Output is correct |
42 |
Correct |
19 ms |
2652 KB |
Output is correct |
43 |
Correct |
27 ms |
2952 KB |
Output is correct |
44 |
Correct |
27 ms |
2908 KB |
Output is correct |
45 |
Correct |
28 ms |
2908 KB |
Output is correct |
46 |
Correct |
16 ms |
2396 KB |
Output is correct |
47 |
Correct |
17 ms |
2652 KB |
Output is correct |
48 |
Correct |
30 ms |
2908 KB |
Output is correct |
49 |
Correct |
33 ms |
3000 KB |
Output is correct |
50 |
Correct |
20 ms |
2652 KB |
Output is correct |
51 |
Correct |
4 ms |
2516 KB |
Output is correct |
52 |
Correct |
37 ms |
2924 KB |
Output is correct |
53 |
Correct |
27 ms |
2908 KB |
Output is correct |
54 |
Correct |
38 ms |
2940 KB |
Output is correct |
55 |
Correct |
74 ms |
3076 KB |
Output is correct |
56 |
Correct |
33 ms |
2900 KB |
Output is correct |
57 |
Correct |
79 ms |
3288 KB |
Output is correct |
58 |
Correct |
41 ms |
2900 KB |
Output is correct |
59 |
Correct |
51 ms |
3076 KB |
Output is correct |
60 |
Correct |
10 ms |
2396 KB |
Output is correct |
61 |
Correct |
62 ms |
3060 KB |
Output is correct |
62 |
Correct |
65 ms |
3284 KB |
Output is correct |
63 |
Correct |
64 ms |
3088 KB |
Output is correct |
64 |
Correct |
61 ms |
3540 KB |
Output is correct |
65 |
Correct |
28 ms |
2652 KB |
Output is correct |
66 |
Correct |
31 ms |
2684 KB |
Output is correct |
67 |
Correct |
62 ms |
3072 KB |
Output is correct |
68 |
Correct |
27 ms |
2396 KB |
Output is correct |
69 |
Correct |
214 ms |
3796 KB |
Output is correct |
70 |
Correct |
122 ms |
3316 KB |
Output is correct |
71 |
Correct |
131 ms |
3288 KB |
Output is correct |
72 |
Correct |
114 ms |
2800 KB |
Output is correct |
73 |
Correct |
115 ms |
2644 KB |
Output is correct |
74 |
Correct |
211 ms |
3800 KB |
Output is correct |
75 |
Correct |
170 ms |
3572 KB |
Output is correct |
76 |
Correct |
229 ms |
3820 KB |
Output is correct |
77 |
Correct |
224 ms |
3792 KB |
Output is correct |