#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstdint>
int x;
int arr[505];
uint32_t knapsack[125005];
int freq[250005];
void knapsack_add(int val) {
for (int i = 125004; i >= val; i--) {
knapsack[i] += knapsack[i-val];
}
}
void knapsack_remove(int val) {
for (int i = 0; i < 125005-val; i++) {
knapsack[i+val] -= knapsack[i];
}
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> x;
int sum = 0;
knapsack[0] = 1;
for (int i = 1; i <= x; i++) {
std::cin >> arr[i];
sum += arr[i];
knapsack_add(arr[i]);
}
#if 0
for (int i = 0; i <= sum; i++) {
std::cout << knapsack[i] << " ";
}
std::cout << "\n";
#endif
if (sum%2==1) {
std::cout << "0\n";
return 0;
}
if (!knapsack[sum/2]) {
std::cout << "0\n";
return 0;
}
for (int i = x; i >= 1; i--) {
sum -= arr[i];
knapsack_remove(arr[i]);
if (i+1<=x) {
sum += arr[i+1];
knapsack_add(arr[i+1]);
}
for (int i = 0; i <= sum/2; i++) {
freq[sum-i-i] += !!knapsack[i];
}
#if 0
for (int i = 0; i <= sum; i++) {
std::cout << knapsack[i] << " ";
}
std::cout << "\n";
#endif
}
std::vector<int> ret;
for (int i = 1; i < 250005; i++) {
#if 0
if (i<=10) {
std::cout << i << " " << freq[i] << "\n";
}
#endif
if (freq[i]==x) {
ret.emplace_back(i);
}
}
std::cout << ret.size() << "\n";
for (const auto& i : ret) {
std::cout << i << " ";
}
std::cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
860 KB |
Output is correct |
13 |
Correct |
6 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
956 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
6 ms |
952 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
860 KB |
Output is correct |
13 |
Correct |
6 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
956 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
6 ms |
952 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
20 ms |
860 KB |
Output is correct |
22 |
Correct |
15 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
960 KB |
Output is correct |
24 |
Correct |
19 ms |
856 KB |
Output is correct |
25 |
Correct |
19 ms |
984 KB |
Output is correct |
26 |
Correct |
20 ms |
856 KB |
Output is correct |
27 |
Correct |
20 ms |
860 KB |
Output is correct |
28 |
Correct |
20 ms |
956 KB |
Output is correct |
29 |
Correct |
20 ms |
860 KB |
Output is correct |
30 |
Correct |
19 ms |
860 KB |
Output is correct |
31 |
Correct |
20 ms |
968 KB |
Output is correct |
32 |
Correct |
20 ms |
860 KB |
Output is correct |
33 |
Correct |
19 ms |
860 KB |
Output is correct |
34 |
Correct |
20 ms |
856 KB |
Output is correct |
35 |
Correct |
19 ms |
860 KB |
Output is correct |
36 |
Correct |
20 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
860 KB |
Output is correct |
13 |
Correct |
6 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
956 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
6 ms |
952 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
20 ms |
860 KB |
Output is correct |
22 |
Correct |
15 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
960 KB |
Output is correct |
24 |
Correct |
19 ms |
856 KB |
Output is correct |
25 |
Correct |
19 ms |
984 KB |
Output is correct |
26 |
Correct |
20 ms |
856 KB |
Output is correct |
27 |
Correct |
20 ms |
860 KB |
Output is correct |
28 |
Correct |
20 ms |
956 KB |
Output is correct |
29 |
Correct |
20 ms |
860 KB |
Output is correct |
30 |
Correct |
19 ms |
860 KB |
Output is correct |
31 |
Correct |
20 ms |
968 KB |
Output is correct |
32 |
Correct |
20 ms |
860 KB |
Output is correct |
33 |
Correct |
19 ms |
860 KB |
Output is correct |
34 |
Correct |
20 ms |
856 KB |
Output is correct |
35 |
Correct |
19 ms |
860 KB |
Output is correct |
36 |
Correct |
20 ms |
972 KB |
Output is correct |
37 |
Correct |
40 ms |
1116 KB |
Output is correct |
38 |
Correct |
41 ms |
1008 KB |
Output is correct |
39 |
Correct |
50 ms |
1168 KB |
Output is correct |
40 |
Correct |
54 ms |
1104 KB |
Output is correct |
41 |
Correct |
56 ms |
1112 KB |
Output is correct |
42 |
Correct |
50 ms |
1204 KB |
Output is correct |
43 |
Correct |
51 ms |
1360 KB |
Output is correct |
44 |
Correct |
51 ms |
1456 KB |
Output is correct |
45 |
Correct |
59 ms |
1364 KB |
Output is correct |
46 |
Correct |
53 ms |
960 KB |
Output is correct |
47 |
Correct |
51 ms |
1108 KB |
Output is correct |
48 |
Correct |
52 ms |
1360 KB |
Output is correct |
49 |
Correct |
62 ms |
1188 KB |
Output is correct |
50 |
Correct |
60 ms |
1116 KB |
Output is correct |
51 |
Correct |
15 ms |
860 KB |
Output is correct |
52 |
Correct |
94 ms |
1460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
860 KB |
Output is correct |
13 |
Correct |
6 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
956 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
6 ms |
952 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
20 ms |
860 KB |
Output is correct |
22 |
Correct |
15 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
960 KB |
Output is correct |
24 |
Correct |
19 ms |
856 KB |
Output is correct |
25 |
Correct |
19 ms |
984 KB |
Output is correct |
26 |
Correct |
20 ms |
856 KB |
Output is correct |
27 |
Correct |
20 ms |
860 KB |
Output is correct |
28 |
Correct |
20 ms |
956 KB |
Output is correct |
29 |
Correct |
20 ms |
860 KB |
Output is correct |
30 |
Correct |
19 ms |
860 KB |
Output is correct |
31 |
Correct |
20 ms |
968 KB |
Output is correct |
32 |
Correct |
20 ms |
860 KB |
Output is correct |
33 |
Correct |
19 ms |
860 KB |
Output is correct |
34 |
Correct |
20 ms |
856 KB |
Output is correct |
35 |
Correct |
19 ms |
860 KB |
Output is correct |
36 |
Correct |
20 ms |
972 KB |
Output is correct |
37 |
Correct |
40 ms |
1116 KB |
Output is correct |
38 |
Correct |
41 ms |
1008 KB |
Output is correct |
39 |
Correct |
50 ms |
1168 KB |
Output is correct |
40 |
Correct |
54 ms |
1104 KB |
Output is correct |
41 |
Correct |
56 ms |
1112 KB |
Output is correct |
42 |
Correct |
50 ms |
1204 KB |
Output is correct |
43 |
Correct |
51 ms |
1360 KB |
Output is correct |
44 |
Correct |
51 ms |
1456 KB |
Output is correct |
45 |
Correct |
59 ms |
1364 KB |
Output is correct |
46 |
Correct |
53 ms |
960 KB |
Output is correct |
47 |
Correct |
51 ms |
1108 KB |
Output is correct |
48 |
Correct |
52 ms |
1360 KB |
Output is correct |
49 |
Correct |
62 ms |
1188 KB |
Output is correct |
50 |
Correct |
60 ms |
1116 KB |
Output is correct |
51 |
Correct |
15 ms |
860 KB |
Output is correct |
52 |
Correct |
94 ms |
1460 KB |
Output is correct |
53 |
Correct |
61 ms |
1364 KB |
Output is correct |
54 |
Correct |
101 ms |
1400 KB |
Output is correct |
55 |
Correct |
113 ms |
1748 KB |
Output is correct |
56 |
Correct |
63 ms |
1364 KB |
Output is correct |
57 |
Correct |
78 ms |
2028 KB |
Output is correct |
58 |
Correct |
73 ms |
1460 KB |
Output is correct |
59 |
Correct |
76 ms |
1620 KB |
Output is correct |
60 |
Correct |
18 ms |
856 KB |
Output is correct |
61 |
Correct |
105 ms |
1748 KB |
Output is correct |
62 |
Correct |
78 ms |
1748 KB |
Output is correct |
63 |
Correct |
77 ms |
1728 KB |
Output is correct |
64 |
Correct |
81 ms |
1728 KB |
Output is correct |
65 |
Correct |
71 ms |
952 KB |
Output is correct |
66 |
Correct |
64 ms |
1140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
2 ms |
788 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
860 KB |
Output is correct |
9 |
Correct |
3 ms |
860 KB |
Output is correct |
10 |
Correct |
6 ms |
860 KB |
Output is correct |
11 |
Correct |
7 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
860 KB |
Output is correct |
13 |
Correct |
6 ms |
860 KB |
Output is correct |
14 |
Correct |
7 ms |
956 KB |
Output is correct |
15 |
Correct |
7 ms |
860 KB |
Output is correct |
16 |
Correct |
7 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
6 ms |
952 KB |
Output is correct |
19 |
Correct |
6 ms |
860 KB |
Output is correct |
20 |
Correct |
6 ms |
860 KB |
Output is correct |
21 |
Correct |
20 ms |
860 KB |
Output is correct |
22 |
Correct |
15 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
960 KB |
Output is correct |
24 |
Correct |
19 ms |
856 KB |
Output is correct |
25 |
Correct |
19 ms |
984 KB |
Output is correct |
26 |
Correct |
20 ms |
856 KB |
Output is correct |
27 |
Correct |
20 ms |
860 KB |
Output is correct |
28 |
Correct |
20 ms |
956 KB |
Output is correct |
29 |
Correct |
20 ms |
860 KB |
Output is correct |
30 |
Correct |
19 ms |
860 KB |
Output is correct |
31 |
Correct |
20 ms |
968 KB |
Output is correct |
32 |
Correct |
20 ms |
860 KB |
Output is correct |
33 |
Correct |
19 ms |
860 KB |
Output is correct |
34 |
Correct |
20 ms |
856 KB |
Output is correct |
35 |
Correct |
19 ms |
860 KB |
Output is correct |
36 |
Correct |
20 ms |
972 KB |
Output is correct |
37 |
Correct |
40 ms |
1116 KB |
Output is correct |
38 |
Correct |
41 ms |
1008 KB |
Output is correct |
39 |
Correct |
50 ms |
1168 KB |
Output is correct |
40 |
Correct |
54 ms |
1104 KB |
Output is correct |
41 |
Correct |
56 ms |
1112 KB |
Output is correct |
42 |
Correct |
50 ms |
1204 KB |
Output is correct |
43 |
Correct |
51 ms |
1360 KB |
Output is correct |
44 |
Correct |
51 ms |
1456 KB |
Output is correct |
45 |
Correct |
59 ms |
1364 KB |
Output is correct |
46 |
Correct |
53 ms |
960 KB |
Output is correct |
47 |
Correct |
51 ms |
1108 KB |
Output is correct |
48 |
Correct |
52 ms |
1360 KB |
Output is correct |
49 |
Correct |
62 ms |
1188 KB |
Output is correct |
50 |
Correct |
60 ms |
1116 KB |
Output is correct |
51 |
Correct |
15 ms |
860 KB |
Output is correct |
52 |
Correct |
94 ms |
1460 KB |
Output is correct |
53 |
Correct |
61 ms |
1364 KB |
Output is correct |
54 |
Correct |
101 ms |
1400 KB |
Output is correct |
55 |
Correct |
113 ms |
1748 KB |
Output is correct |
56 |
Correct |
63 ms |
1364 KB |
Output is correct |
57 |
Correct |
78 ms |
2028 KB |
Output is correct |
58 |
Correct |
73 ms |
1460 KB |
Output is correct |
59 |
Correct |
76 ms |
1620 KB |
Output is correct |
60 |
Correct |
18 ms |
856 KB |
Output is correct |
61 |
Correct |
105 ms |
1748 KB |
Output is correct |
62 |
Correct |
78 ms |
1748 KB |
Output is correct |
63 |
Correct |
77 ms |
1728 KB |
Output is correct |
64 |
Correct |
81 ms |
1728 KB |
Output is correct |
65 |
Correct |
71 ms |
952 KB |
Output is correct |
66 |
Correct |
64 ms |
1140 KB |
Output is correct |
67 |
Correct |
87 ms |
1632 KB |
Output is correct |
68 |
Correct |
32 ms |
936 KB |
Output is correct |
69 |
Correct |
137 ms |
2868 KB |
Output is correct |
70 |
Correct |
127 ms |
2080 KB |
Output is correct |
71 |
Correct |
121 ms |
2104 KB |
Output is correct |
72 |
Correct |
136 ms |
1364 KB |
Output is correct |
73 |
Correct |
113 ms |
1420 KB |
Output is correct |
74 |
Correct |
137 ms |
3028 KB |
Output is correct |
75 |
Correct |
131 ms |
2524 KB |
Output is correct |
76 |
Correct |
132 ms |
3040 KB |
Output is correct |
77 |
Correct |
141 ms |
3004 KB |
Output is correct |