#include <bits/stdc++.h>
using namespace std;
const int mod[] = {(int)1e9 + 7, (int)1e9 + 9};
void addSelf(int &x, int y, int mod) {
x += y;
if (x >= mod) {
x -= mod;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
int sum = accumulate(a.begin(), a.end(), 0);
vector<vector<int>> dp(sum + 1, vector<int>(2));
dp[0][0] = dp[0][1] = 1;
for (const int &x : a) {
for (int i = sum; i >= x; --i) {
for (int j = 0; j < 2; ++j) {
addSelf(dp[i][j], dp[i - x][j], mod[j]);
}
}
}
if (sum % 2 == 1 || dp[sum / 2] == vector<int>(2)) {
cout << "0\n";
return 0;
}
vector<bool> wt(sum + 1, true);
vector<vector<int>> newDp(sum + 1, vector<int>(2));
for (const int &x : a) {
newDp = dp;
for (int i = x; i <= sum; ++i) {
for (int j = 0; j < 2; ++j) {
addSelf(newDp[i][j], mod[j] - newDp[i - x][j], mod[j]);
}
}
for (int i = 1; i <= sum; ++i) {
int newSum = sum - x + i;
if (newSum % 2 == 1 || newDp[newSum / 2] == vector<int>(2)) {
wt[i] = false;
}
}
}
cout << count(wt.begin() + 1, wt.end(), true) << '\n';
for (int i = 1; i <= sum; ++i) {
if (wt[i]) {
cout << i << ' ';
}
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
596 KB |
Output is correct |
22 |
Correct |
7 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
572 KB |
Output is correct |
24 |
Correct |
11 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
1212 KB |
Output is correct |
26 |
Correct |
22 ms |
1364 KB |
Output is correct |
27 |
Correct |
20 ms |
1300 KB |
Output is correct |
28 |
Correct |
22 ms |
1364 KB |
Output is correct |
29 |
Correct |
23 ms |
1364 KB |
Output is correct |
30 |
Correct |
13 ms |
852 KB |
Output is correct |
31 |
Correct |
17 ms |
1108 KB |
Output is correct |
32 |
Correct |
11 ms |
844 KB |
Output is correct |
33 |
Correct |
25 ms |
1364 KB |
Output is correct |
34 |
Correct |
22 ms |
1396 KB |
Output is correct |
35 |
Correct |
22 ms |
1400 KB |
Output is correct |
36 |
Correct |
11 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
596 KB |
Output is correct |
22 |
Correct |
7 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
572 KB |
Output is correct |
24 |
Correct |
11 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
1212 KB |
Output is correct |
26 |
Correct |
22 ms |
1364 KB |
Output is correct |
27 |
Correct |
20 ms |
1300 KB |
Output is correct |
28 |
Correct |
22 ms |
1364 KB |
Output is correct |
29 |
Correct |
23 ms |
1364 KB |
Output is correct |
30 |
Correct |
13 ms |
852 KB |
Output is correct |
31 |
Correct |
17 ms |
1108 KB |
Output is correct |
32 |
Correct |
11 ms |
844 KB |
Output is correct |
33 |
Correct |
25 ms |
1364 KB |
Output is correct |
34 |
Correct |
22 ms |
1396 KB |
Output is correct |
35 |
Correct |
22 ms |
1400 KB |
Output is correct |
36 |
Correct |
11 ms |
724 KB |
Output is correct |
37 |
Correct |
85 ms |
2388 KB |
Output is correct |
38 |
Correct |
93 ms |
2496 KB |
Output is correct |
39 |
Correct |
361 ms |
7156 KB |
Output is correct |
40 |
Correct |
214 ms |
3868 KB |
Output is correct |
41 |
Correct |
443 ms |
8404 KB |
Output is correct |
42 |
Correct |
165 ms |
3620 KB |
Output is correct |
43 |
Correct |
300 ms |
6604 KB |
Output is correct |
44 |
Correct |
310 ms |
6600 KB |
Output is correct |
45 |
Correct |
309 ms |
6620 KB |
Output is correct |
46 |
Correct |
187 ms |
3772 KB |
Output is correct |
47 |
Correct |
181 ms |
3916 KB |
Output is correct |
48 |
Correct |
333 ms |
7144 KB |
Output is correct |
49 |
Correct |
341 ms |
7100 KB |
Output is correct |
50 |
Correct |
186 ms |
3908 KB |
Output is correct |
51 |
Correct |
32 ms |
2004 KB |
Output is correct |
52 |
Correct |
417 ms |
8132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
596 KB |
Output is correct |
22 |
Correct |
7 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
572 KB |
Output is correct |
24 |
Correct |
11 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
1212 KB |
Output is correct |
26 |
Correct |
22 ms |
1364 KB |
Output is correct |
27 |
Correct |
20 ms |
1300 KB |
Output is correct |
28 |
Correct |
22 ms |
1364 KB |
Output is correct |
29 |
Correct |
23 ms |
1364 KB |
Output is correct |
30 |
Correct |
13 ms |
852 KB |
Output is correct |
31 |
Correct |
17 ms |
1108 KB |
Output is correct |
32 |
Correct |
11 ms |
844 KB |
Output is correct |
33 |
Correct |
25 ms |
1364 KB |
Output is correct |
34 |
Correct |
22 ms |
1396 KB |
Output is correct |
35 |
Correct |
22 ms |
1400 KB |
Output is correct |
36 |
Correct |
11 ms |
724 KB |
Output is correct |
37 |
Correct |
85 ms |
2388 KB |
Output is correct |
38 |
Correct |
93 ms |
2496 KB |
Output is correct |
39 |
Correct |
361 ms |
7156 KB |
Output is correct |
40 |
Correct |
214 ms |
3868 KB |
Output is correct |
41 |
Correct |
443 ms |
8404 KB |
Output is correct |
42 |
Correct |
165 ms |
3620 KB |
Output is correct |
43 |
Correct |
300 ms |
6604 KB |
Output is correct |
44 |
Correct |
310 ms |
6600 KB |
Output is correct |
45 |
Correct |
309 ms |
6620 KB |
Output is correct |
46 |
Correct |
187 ms |
3772 KB |
Output is correct |
47 |
Correct |
181 ms |
3916 KB |
Output is correct |
48 |
Correct |
333 ms |
7144 KB |
Output is correct |
49 |
Correct |
341 ms |
7100 KB |
Output is correct |
50 |
Correct |
186 ms |
3908 KB |
Output is correct |
51 |
Correct |
32 ms |
2004 KB |
Output is correct |
52 |
Correct |
417 ms |
8132 KB |
Output is correct |
53 |
Correct |
298 ms |
5436 KB |
Output is correct |
54 |
Correct |
484 ms |
6536 KB |
Output is correct |
55 |
Correct |
964 ms |
12796 KB |
Output is correct |
56 |
Correct |
368 ms |
6568 KB |
Output is correct |
57 |
Correct |
961 ms |
13436 KB |
Output is correct |
58 |
Correct |
476 ms |
7148 KB |
Output is correct |
59 |
Correct |
573 ms |
8908 KB |
Output is correct |
60 |
Correct |
80 ms |
3652 KB |
Output is correct |
61 |
Correct |
708 ms |
9848 KB |
Output is correct |
62 |
Correct |
831 ms |
11064 KB |
Output is correct |
63 |
Correct |
945 ms |
12016 KB |
Output is correct |
64 |
Correct |
737 ms |
11812 KB |
Output is correct |
65 |
Correct |
341 ms |
5520 KB |
Output is correct |
66 |
Correct |
410 ms |
6172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
452 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
596 KB |
Output is correct |
22 |
Correct |
7 ms |
596 KB |
Output is correct |
23 |
Correct |
3 ms |
572 KB |
Output is correct |
24 |
Correct |
11 ms |
724 KB |
Output is correct |
25 |
Correct |
22 ms |
1212 KB |
Output is correct |
26 |
Correct |
22 ms |
1364 KB |
Output is correct |
27 |
Correct |
20 ms |
1300 KB |
Output is correct |
28 |
Correct |
22 ms |
1364 KB |
Output is correct |
29 |
Correct |
23 ms |
1364 KB |
Output is correct |
30 |
Correct |
13 ms |
852 KB |
Output is correct |
31 |
Correct |
17 ms |
1108 KB |
Output is correct |
32 |
Correct |
11 ms |
844 KB |
Output is correct |
33 |
Correct |
25 ms |
1364 KB |
Output is correct |
34 |
Correct |
22 ms |
1396 KB |
Output is correct |
35 |
Correct |
22 ms |
1400 KB |
Output is correct |
36 |
Correct |
11 ms |
724 KB |
Output is correct |
37 |
Correct |
85 ms |
2388 KB |
Output is correct |
38 |
Correct |
93 ms |
2496 KB |
Output is correct |
39 |
Correct |
361 ms |
7156 KB |
Output is correct |
40 |
Correct |
214 ms |
3868 KB |
Output is correct |
41 |
Correct |
443 ms |
8404 KB |
Output is correct |
42 |
Correct |
165 ms |
3620 KB |
Output is correct |
43 |
Correct |
300 ms |
6604 KB |
Output is correct |
44 |
Correct |
310 ms |
6600 KB |
Output is correct |
45 |
Correct |
309 ms |
6620 KB |
Output is correct |
46 |
Correct |
187 ms |
3772 KB |
Output is correct |
47 |
Correct |
181 ms |
3916 KB |
Output is correct |
48 |
Correct |
333 ms |
7144 KB |
Output is correct |
49 |
Correct |
341 ms |
7100 KB |
Output is correct |
50 |
Correct |
186 ms |
3908 KB |
Output is correct |
51 |
Correct |
32 ms |
2004 KB |
Output is correct |
52 |
Correct |
417 ms |
8132 KB |
Output is correct |
53 |
Correct |
298 ms |
5436 KB |
Output is correct |
54 |
Correct |
484 ms |
6536 KB |
Output is correct |
55 |
Correct |
964 ms |
12796 KB |
Output is correct |
56 |
Correct |
368 ms |
6568 KB |
Output is correct |
57 |
Correct |
961 ms |
13436 KB |
Output is correct |
58 |
Correct |
476 ms |
7148 KB |
Output is correct |
59 |
Correct |
573 ms |
8908 KB |
Output is correct |
60 |
Correct |
80 ms |
3652 KB |
Output is correct |
61 |
Correct |
708 ms |
9848 KB |
Output is correct |
62 |
Correct |
831 ms |
11064 KB |
Output is correct |
63 |
Correct |
945 ms |
12016 KB |
Output is correct |
64 |
Correct |
737 ms |
11812 KB |
Output is correct |
65 |
Correct |
341 ms |
5520 KB |
Output is correct |
66 |
Correct |
410 ms |
6172 KB |
Output is correct |
67 |
Correct |
697 ms |
9220 KB |
Output is correct |
68 |
Correct |
244 ms |
6996 KB |
Output is correct |
69 |
Execution timed out |
1092 ms |
23444 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |