#include "bits/stdc++.h"
using namespace std;
const int mod = 998244353, mod2 = (int) 1e9 + 7;
const int N = 500 * 500 + 22;
int dp[N], dp2[N];
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int S = std::accumulate(a.begin(), a.end(), 0);
dp[0] = dp2[0] = 1;
for (auto& x : a) {
for (int j = N - 1; j >= x; j--) {
dp[j] += dp[j - x];
if (dp[j] >= mod) {
dp[j] -= mod;
}
dp2[j] += dp2[j - x];
if (dp2[j] >= mod2) {
dp2[j] -= mod2;
}
}
}
vector<int> good(S, 0);
if (S % 2 != 0 || (dp[S / 2] == 0 && dp2[S / 2] == 0)) {
cout << 0 << '\n';
return;
}
for (int i = 0; i < n; i++) {
int x = a[i];
for (int j = x; j < N; j++) {
dp[j] -= dp[j - x];
if (dp[j] < 0) {
dp[j] += mod;
}
dp2[j] -= dp2[j - x];
if (dp2[j] < 0) {
dp2[j] += mod2;
}
}
for (int val = 1; val < S; val++) {
int Sval = S + val - x;
if (Sval % 2 != 0 || (dp[Sval / 2] == 0 && dp2[Sval / 2] == 0)) {
continue;
}
good[val]++;
}
for (int j = N - 1; j >= x; j--) {
dp[j] += dp[j - x];
if (dp[j] >= mod) {
dp[j] -= mod;
}
dp2[j] += dp2[j - x];
if (dp2[j] >= mod2) {
dp2[j] -= mod2;
}
}
}
vector<int> ans;
for (int i = 0; i < S; i++) {
if (good[i] == n) {
ans.push_back(i);
}
}
cout << ans.size() << '\n';
for (auto& i : ans) {
cout << i << " ";
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
10 |
Correct |
32 ms |
2384 KB |
Output is correct |
11 |
Correct |
39 ms |
2552 KB |
Output is correct |
12 |
Correct |
46 ms |
2412 KB |
Output is correct |
13 |
Correct |
31 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2384 KB |
Output is correct |
15 |
Correct |
33 ms |
2384 KB |
Output is correct |
16 |
Correct |
56 ms |
2384 KB |
Output is correct |
17 |
Correct |
38 ms |
2384 KB |
Output is correct |
18 |
Correct |
30 ms |
2384 KB |
Output is correct |
19 |
Correct |
43 ms |
2552 KB |
Output is correct |
20 |
Correct |
34 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
10 |
Correct |
32 ms |
2384 KB |
Output is correct |
11 |
Correct |
39 ms |
2552 KB |
Output is correct |
12 |
Correct |
46 ms |
2412 KB |
Output is correct |
13 |
Correct |
31 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2384 KB |
Output is correct |
15 |
Correct |
33 ms |
2384 KB |
Output is correct |
16 |
Correct |
56 ms |
2384 KB |
Output is correct |
17 |
Correct |
38 ms |
2384 KB |
Output is correct |
18 |
Correct |
30 ms |
2384 KB |
Output is correct |
19 |
Correct |
43 ms |
2552 KB |
Output is correct |
20 |
Correct |
34 ms |
2384 KB |
Output is correct |
21 |
Correct |
98 ms |
2384 KB |
Output is correct |
22 |
Correct |
83 ms |
2404 KB |
Output is correct |
23 |
Correct |
65 ms |
2384 KB |
Output is correct |
24 |
Correct |
110 ms |
2564 KB |
Output is correct |
25 |
Correct |
117 ms |
2384 KB |
Output is correct |
26 |
Correct |
111 ms |
2380 KB |
Output is correct |
27 |
Correct |
110 ms |
2416 KB |
Output is correct |
28 |
Correct |
126 ms |
2412 KB |
Output is correct |
29 |
Correct |
109 ms |
2384 KB |
Output is correct |
30 |
Correct |
111 ms |
2384 KB |
Output is correct |
31 |
Correct |
108 ms |
2552 KB |
Output is correct |
32 |
Correct |
115 ms |
2384 KB |
Output is correct |
33 |
Correct |
128 ms |
2408 KB |
Output is correct |
34 |
Correct |
107 ms |
2384 KB |
Output is correct |
35 |
Correct |
107 ms |
2412 KB |
Output is correct |
36 |
Correct |
148 ms |
2416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
10 |
Correct |
32 ms |
2384 KB |
Output is correct |
11 |
Correct |
39 ms |
2552 KB |
Output is correct |
12 |
Correct |
46 ms |
2412 KB |
Output is correct |
13 |
Correct |
31 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2384 KB |
Output is correct |
15 |
Correct |
33 ms |
2384 KB |
Output is correct |
16 |
Correct |
56 ms |
2384 KB |
Output is correct |
17 |
Correct |
38 ms |
2384 KB |
Output is correct |
18 |
Correct |
30 ms |
2384 KB |
Output is correct |
19 |
Correct |
43 ms |
2552 KB |
Output is correct |
20 |
Correct |
34 ms |
2384 KB |
Output is correct |
21 |
Correct |
98 ms |
2384 KB |
Output is correct |
22 |
Correct |
83 ms |
2404 KB |
Output is correct |
23 |
Correct |
65 ms |
2384 KB |
Output is correct |
24 |
Correct |
110 ms |
2564 KB |
Output is correct |
25 |
Correct |
117 ms |
2384 KB |
Output is correct |
26 |
Correct |
111 ms |
2380 KB |
Output is correct |
27 |
Correct |
110 ms |
2416 KB |
Output is correct |
28 |
Correct |
126 ms |
2412 KB |
Output is correct |
29 |
Correct |
109 ms |
2384 KB |
Output is correct |
30 |
Correct |
111 ms |
2384 KB |
Output is correct |
31 |
Correct |
108 ms |
2552 KB |
Output is correct |
32 |
Correct |
115 ms |
2384 KB |
Output is correct |
33 |
Correct |
128 ms |
2408 KB |
Output is correct |
34 |
Correct |
107 ms |
2384 KB |
Output is correct |
35 |
Correct |
107 ms |
2412 KB |
Output is correct |
36 |
Correct |
148 ms |
2416 KB |
Output is correct |
37 |
Correct |
227 ms |
2408 KB |
Output is correct |
38 |
Correct |
269 ms |
2484 KB |
Output is correct |
39 |
Correct |
304 ms |
2416 KB |
Output is correct |
40 |
Correct |
355 ms |
2632 KB |
Output is correct |
41 |
Correct |
315 ms |
2664 KB |
Output is correct |
42 |
Correct |
262 ms |
2632 KB |
Output is correct |
43 |
Correct |
262 ms |
2892 KB |
Output is correct |
44 |
Correct |
273 ms |
3016 KB |
Output is correct |
45 |
Correct |
260 ms |
2896 KB |
Output is correct |
46 |
Correct |
299 ms |
2384 KB |
Output is correct |
47 |
Correct |
307 ms |
2660 KB |
Output is correct |
48 |
Correct |
280 ms |
2888 KB |
Output is correct |
49 |
Correct |
266 ms |
2632 KB |
Output is correct |
50 |
Correct |
273 ms |
2668 KB |
Output is correct |
51 |
Correct |
174 ms |
2384 KB |
Output is correct |
52 |
Correct |
324 ms |
2920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
10 |
Correct |
32 ms |
2384 KB |
Output is correct |
11 |
Correct |
39 ms |
2552 KB |
Output is correct |
12 |
Correct |
46 ms |
2412 KB |
Output is correct |
13 |
Correct |
31 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2384 KB |
Output is correct |
15 |
Correct |
33 ms |
2384 KB |
Output is correct |
16 |
Correct |
56 ms |
2384 KB |
Output is correct |
17 |
Correct |
38 ms |
2384 KB |
Output is correct |
18 |
Correct |
30 ms |
2384 KB |
Output is correct |
19 |
Correct |
43 ms |
2552 KB |
Output is correct |
20 |
Correct |
34 ms |
2384 KB |
Output is correct |
21 |
Correct |
98 ms |
2384 KB |
Output is correct |
22 |
Correct |
83 ms |
2404 KB |
Output is correct |
23 |
Correct |
65 ms |
2384 KB |
Output is correct |
24 |
Correct |
110 ms |
2564 KB |
Output is correct |
25 |
Correct |
117 ms |
2384 KB |
Output is correct |
26 |
Correct |
111 ms |
2380 KB |
Output is correct |
27 |
Correct |
110 ms |
2416 KB |
Output is correct |
28 |
Correct |
126 ms |
2412 KB |
Output is correct |
29 |
Correct |
109 ms |
2384 KB |
Output is correct |
30 |
Correct |
111 ms |
2384 KB |
Output is correct |
31 |
Correct |
108 ms |
2552 KB |
Output is correct |
32 |
Correct |
115 ms |
2384 KB |
Output is correct |
33 |
Correct |
128 ms |
2408 KB |
Output is correct |
34 |
Correct |
107 ms |
2384 KB |
Output is correct |
35 |
Correct |
107 ms |
2412 KB |
Output is correct |
36 |
Correct |
148 ms |
2416 KB |
Output is correct |
37 |
Correct |
227 ms |
2408 KB |
Output is correct |
38 |
Correct |
269 ms |
2484 KB |
Output is correct |
39 |
Correct |
304 ms |
2416 KB |
Output is correct |
40 |
Correct |
355 ms |
2632 KB |
Output is correct |
41 |
Correct |
315 ms |
2664 KB |
Output is correct |
42 |
Correct |
262 ms |
2632 KB |
Output is correct |
43 |
Correct |
262 ms |
2892 KB |
Output is correct |
44 |
Correct |
273 ms |
3016 KB |
Output is correct |
45 |
Correct |
260 ms |
2896 KB |
Output is correct |
46 |
Correct |
299 ms |
2384 KB |
Output is correct |
47 |
Correct |
307 ms |
2660 KB |
Output is correct |
48 |
Correct |
280 ms |
2888 KB |
Output is correct |
49 |
Correct |
266 ms |
2632 KB |
Output is correct |
50 |
Correct |
273 ms |
2668 KB |
Output is correct |
51 |
Correct |
174 ms |
2384 KB |
Output is correct |
52 |
Correct |
324 ms |
2920 KB |
Output is correct |
53 |
Correct |
362 ms |
2888 KB |
Output is correct |
54 |
Correct |
382 ms |
2880 KB |
Output is correct |
55 |
Correct |
484 ms |
3236 KB |
Output is correct |
56 |
Correct |
359 ms |
2916 KB |
Output is correct |
57 |
Correct |
451 ms |
3316 KB |
Output is correct |
58 |
Correct |
403 ms |
2908 KB |
Output is correct |
59 |
Correct |
450 ms |
3056 KB |
Output is correct |
60 |
Correct |
174 ms |
2404 KB |
Output is correct |
61 |
Correct |
453 ms |
3052 KB |
Output is correct |
62 |
Correct |
487 ms |
3300 KB |
Output is correct |
63 |
Correct |
415 ms |
3304 KB |
Output is correct |
64 |
Correct |
423 ms |
3276 KB |
Output is correct |
65 |
Correct |
395 ms |
2404 KB |
Output is correct |
66 |
Correct |
408 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
2592 KB |
Output is correct |
3 |
Correct |
5 ms |
2384 KB |
Output is correct |
4 |
Correct |
8 ms |
2384 KB |
Output is correct |
5 |
Correct |
25 ms |
2384 KB |
Output is correct |
6 |
Correct |
12 ms |
2384 KB |
Output is correct |
7 |
Correct |
9 ms |
2384 KB |
Output is correct |
8 |
Correct |
15 ms |
2384 KB |
Output is correct |
9 |
Correct |
16 ms |
2384 KB |
Output is correct |
10 |
Correct |
32 ms |
2384 KB |
Output is correct |
11 |
Correct |
39 ms |
2552 KB |
Output is correct |
12 |
Correct |
46 ms |
2412 KB |
Output is correct |
13 |
Correct |
31 ms |
2384 KB |
Output is correct |
14 |
Correct |
36 ms |
2384 KB |
Output is correct |
15 |
Correct |
33 ms |
2384 KB |
Output is correct |
16 |
Correct |
56 ms |
2384 KB |
Output is correct |
17 |
Correct |
38 ms |
2384 KB |
Output is correct |
18 |
Correct |
30 ms |
2384 KB |
Output is correct |
19 |
Correct |
43 ms |
2552 KB |
Output is correct |
20 |
Correct |
34 ms |
2384 KB |
Output is correct |
21 |
Correct |
98 ms |
2384 KB |
Output is correct |
22 |
Correct |
83 ms |
2404 KB |
Output is correct |
23 |
Correct |
65 ms |
2384 KB |
Output is correct |
24 |
Correct |
110 ms |
2564 KB |
Output is correct |
25 |
Correct |
117 ms |
2384 KB |
Output is correct |
26 |
Correct |
111 ms |
2380 KB |
Output is correct |
27 |
Correct |
110 ms |
2416 KB |
Output is correct |
28 |
Correct |
126 ms |
2412 KB |
Output is correct |
29 |
Correct |
109 ms |
2384 KB |
Output is correct |
30 |
Correct |
111 ms |
2384 KB |
Output is correct |
31 |
Correct |
108 ms |
2552 KB |
Output is correct |
32 |
Correct |
115 ms |
2384 KB |
Output is correct |
33 |
Correct |
128 ms |
2408 KB |
Output is correct |
34 |
Correct |
107 ms |
2384 KB |
Output is correct |
35 |
Correct |
107 ms |
2412 KB |
Output is correct |
36 |
Correct |
148 ms |
2416 KB |
Output is correct |
37 |
Correct |
227 ms |
2408 KB |
Output is correct |
38 |
Correct |
269 ms |
2484 KB |
Output is correct |
39 |
Correct |
304 ms |
2416 KB |
Output is correct |
40 |
Correct |
355 ms |
2632 KB |
Output is correct |
41 |
Correct |
315 ms |
2664 KB |
Output is correct |
42 |
Correct |
262 ms |
2632 KB |
Output is correct |
43 |
Correct |
262 ms |
2892 KB |
Output is correct |
44 |
Correct |
273 ms |
3016 KB |
Output is correct |
45 |
Correct |
260 ms |
2896 KB |
Output is correct |
46 |
Correct |
299 ms |
2384 KB |
Output is correct |
47 |
Correct |
307 ms |
2660 KB |
Output is correct |
48 |
Correct |
280 ms |
2888 KB |
Output is correct |
49 |
Correct |
266 ms |
2632 KB |
Output is correct |
50 |
Correct |
273 ms |
2668 KB |
Output is correct |
51 |
Correct |
174 ms |
2384 KB |
Output is correct |
52 |
Correct |
324 ms |
2920 KB |
Output is correct |
53 |
Correct |
362 ms |
2888 KB |
Output is correct |
54 |
Correct |
382 ms |
2880 KB |
Output is correct |
55 |
Correct |
484 ms |
3236 KB |
Output is correct |
56 |
Correct |
359 ms |
2916 KB |
Output is correct |
57 |
Correct |
451 ms |
3316 KB |
Output is correct |
58 |
Correct |
403 ms |
2908 KB |
Output is correct |
59 |
Correct |
450 ms |
3056 KB |
Output is correct |
60 |
Correct |
174 ms |
2404 KB |
Output is correct |
61 |
Correct |
453 ms |
3052 KB |
Output is correct |
62 |
Correct |
487 ms |
3300 KB |
Output is correct |
63 |
Correct |
415 ms |
3304 KB |
Output is correct |
64 |
Correct |
423 ms |
3276 KB |
Output is correct |
65 |
Correct |
395 ms |
2404 KB |
Output is correct |
66 |
Correct |
408 ms |
2632 KB |
Output is correct |
67 |
Correct |
578 ms |
3056 KB |
Output is correct |
68 |
Correct |
255 ms |
2668 KB |
Output is correct |
69 |
Correct |
667 ms |
4324 KB |
Output is correct |
70 |
Correct |
655 ms |
3564 KB |
Output is correct |
71 |
Correct |
663 ms |
3540 KB |
Output is correct |
72 |
Correct |
709 ms |
2664 KB |
Output is correct |
73 |
Correct |
633 ms |
2888 KB |
Output is correct |
74 |
Correct |
713 ms |
4316 KB |
Output is correct |
75 |
Correct |
651 ms |
4036 KB |
Output is correct |
76 |
Correct |
714 ms |
4324 KB |
Output is correct |
77 |
Correct |
721 ms |
4572 KB |
Output is correct |