#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ff first
#define ss second
typedef long long ll;
using namespace std;
const int P1 = 727196341;
const int P2 = 271915031;
const int N = 500 + 10;
int a[N];
int dp1[N * N];
int dp2[N * N];
int cnt[N * N];
void add(int x, int k) {
for (int i = k; i >= x; i--) {
dp1[i] = (dp1[i - x] + dp1[i]) % P1;
dp2[i] = (dp2[i - x] + dp2[i]) % P2;
}
}
void sub(int x, int sm) {
for (int i = x; i <= sm; i++) {
dp1[i] = (dp1[i] - dp1[i - x] + P1) % P1;
dp2[i] = (dp2[i] - dp2[i - x] + P2) % P2;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n;
cin >> n;
int sm = 0;
dp1[0] = 1;
dp2[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sm += a[i];
add(a[i], sm);
}
if (sm % 2 != 0) {
cout << 0 << "\n";
return 0;
}
if (dp1[sm / 2] == 0 && dp2[sm / 2] == 0) {
cout << 0 << "\n";
return 0;
}
for (int i = 1; i <= n; i++) {
sub(a[i], sm);
sm -= a[i];
for (int i = 0; 2 * i < sm; i++) {
if ((dp1[i] != 0 || dp2[i] != 0)) {
cnt[sm - 2 * i]++;
}
}
sm += a[i];
add(a[i], sm);
}
vector <int> ans;
for (int i = 1; i < N * N; i++) {
if (cnt[i] == n) ans.push_back(i);
}
cout << (int)ans.size() << "\n";
for (auto it : ans) {
cout << it << " ";
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
3 ms |
2556 KB |
Output is correct |
22 |
Correct |
3 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2540 KB |
Output is correct |
24 |
Correct |
4 ms |
2552 KB |
Output is correct |
25 |
Correct |
6 ms |
2384 KB |
Output is correct |
26 |
Correct |
7 ms |
2552 KB |
Output is correct |
27 |
Correct |
7 ms |
2384 KB |
Output is correct |
28 |
Correct |
7 ms |
2384 KB |
Output is correct |
29 |
Correct |
8 ms |
2552 KB |
Output is correct |
30 |
Correct |
6 ms |
2384 KB |
Output is correct |
31 |
Correct |
6 ms |
2384 KB |
Output is correct |
32 |
Correct |
5 ms |
2384 KB |
Output is correct |
33 |
Correct |
7 ms |
2516 KB |
Output is correct |
34 |
Correct |
8 ms |
2384 KB |
Output is correct |
35 |
Correct |
7 ms |
2384 KB |
Output is correct |
36 |
Correct |
5 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
3 ms |
2556 KB |
Output is correct |
22 |
Correct |
3 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2540 KB |
Output is correct |
24 |
Correct |
4 ms |
2552 KB |
Output is correct |
25 |
Correct |
6 ms |
2384 KB |
Output is correct |
26 |
Correct |
7 ms |
2552 KB |
Output is correct |
27 |
Correct |
7 ms |
2384 KB |
Output is correct |
28 |
Correct |
7 ms |
2384 KB |
Output is correct |
29 |
Correct |
8 ms |
2552 KB |
Output is correct |
30 |
Correct |
6 ms |
2384 KB |
Output is correct |
31 |
Correct |
6 ms |
2384 KB |
Output is correct |
32 |
Correct |
5 ms |
2384 KB |
Output is correct |
33 |
Correct |
7 ms |
2516 KB |
Output is correct |
34 |
Correct |
8 ms |
2384 KB |
Output is correct |
35 |
Correct |
7 ms |
2384 KB |
Output is correct |
36 |
Correct |
5 ms |
2384 KB |
Output is correct |
37 |
Correct |
26 ms |
2632 KB |
Output is correct |
38 |
Correct |
27 ms |
2584 KB |
Output is correct |
39 |
Correct |
101 ms |
2640 KB |
Output is correct |
40 |
Correct |
62 ms |
2632 KB |
Output is correct |
41 |
Correct |
138 ms |
2776 KB |
Output is correct |
42 |
Correct |
53 ms |
2624 KB |
Output is correct |
43 |
Correct |
89 ms |
2964 KB |
Output is correct |
44 |
Correct |
104 ms |
2968 KB |
Output is correct |
45 |
Correct |
94 ms |
2888 KB |
Output is correct |
46 |
Correct |
81 ms |
2524 KB |
Output is correct |
47 |
Correct |
63 ms |
2640 KB |
Output is correct |
48 |
Correct |
101 ms |
2984 KB |
Output is correct |
49 |
Correct |
108 ms |
2640 KB |
Output is correct |
50 |
Correct |
56 ms |
2640 KB |
Output is correct |
51 |
Correct |
10 ms |
2384 KB |
Output is correct |
52 |
Correct |
126 ms |
3076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
3 ms |
2556 KB |
Output is correct |
22 |
Correct |
3 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2540 KB |
Output is correct |
24 |
Correct |
4 ms |
2552 KB |
Output is correct |
25 |
Correct |
6 ms |
2384 KB |
Output is correct |
26 |
Correct |
7 ms |
2552 KB |
Output is correct |
27 |
Correct |
7 ms |
2384 KB |
Output is correct |
28 |
Correct |
7 ms |
2384 KB |
Output is correct |
29 |
Correct |
8 ms |
2552 KB |
Output is correct |
30 |
Correct |
6 ms |
2384 KB |
Output is correct |
31 |
Correct |
6 ms |
2384 KB |
Output is correct |
32 |
Correct |
5 ms |
2384 KB |
Output is correct |
33 |
Correct |
7 ms |
2516 KB |
Output is correct |
34 |
Correct |
8 ms |
2384 KB |
Output is correct |
35 |
Correct |
7 ms |
2384 KB |
Output is correct |
36 |
Correct |
5 ms |
2384 KB |
Output is correct |
37 |
Correct |
26 ms |
2632 KB |
Output is correct |
38 |
Correct |
27 ms |
2584 KB |
Output is correct |
39 |
Correct |
101 ms |
2640 KB |
Output is correct |
40 |
Correct |
62 ms |
2632 KB |
Output is correct |
41 |
Correct |
138 ms |
2776 KB |
Output is correct |
42 |
Correct |
53 ms |
2624 KB |
Output is correct |
43 |
Correct |
89 ms |
2964 KB |
Output is correct |
44 |
Correct |
104 ms |
2968 KB |
Output is correct |
45 |
Correct |
94 ms |
2888 KB |
Output is correct |
46 |
Correct |
81 ms |
2524 KB |
Output is correct |
47 |
Correct |
63 ms |
2640 KB |
Output is correct |
48 |
Correct |
101 ms |
2984 KB |
Output is correct |
49 |
Correct |
108 ms |
2640 KB |
Output is correct |
50 |
Correct |
56 ms |
2640 KB |
Output is correct |
51 |
Correct |
10 ms |
2384 KB |
Output is correct |
52 |
Correct |
126 ms |
3076 KB |
Output is correct |
53 |
Correct |
98 ms |
2892 KB |
Output is correct |
54 |
Correct |
128 ms |
2888 KB |
Output is correct |
55 |
Correct |
283 ms |
3496 KB |
Output is correct |
56 |
Correct |
113 ms |
2888 KB |
Output is correct |
57 |
Correct |
288 ms |
3532 KB |
Output is correct |
58 |
Correct |
144 ms |
3144 KB |
Output is correct |
59 |
Correct |
183 ms |
3276 KB |
Output is correct |
60 |
Correct |
25 ms |
2552 KB |
Output is correct |
61 |
Correct |
205 ms |
3212 KB |
Output is correct |
62 |
Correct |
199 ms |
3276 KB |
Output is correct |
63 |
Correct |
222 ms |
3276 KB |
Output is correct |
64 |
Correct |
213 ms |
3496 KB |
Output is correct |
65 |
Correct |
102 ms |
2640 KB |
Output is correct |
66 |
Correct |
108 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
1 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
1 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
13 |
Correct |
1 ms |
2384 KB |
Output is correct |
14 |
Correct |
1 ms |
2384 KB |
Output is correct |
15 |
Correct |
1 ms |
2384 KB |
Output is correct |
16 |
Correct |
1 ms |
2384 KB |
Output is correct |
17 |
Correct |
1 ms |
2384 KB |
Output is correct |
18 |
Correct |
1 ms |
2384 KB |
Output is correct |
19 |
Correct |
2 ms |
2384 KB |
Output is correct |
20 |
Correct |
1 ms |
2384 KB |
Output is correct |
21 |
Correct |
3 ms |
2556 KB |
Output is correct |
22 |
Correct |
3 ms |
2384 KB |
Output is correct |
23 |
Correct |
2 ms |
2540 KB |
Output is correct |
24 |
Correct |
4 ms |
2552 KB |
Output is correct |
25 |
Correct |
6 ms |
2384 KB |
Output is correct |
26 |
Correct |
7 ms |
2552 KB |
Output is correct |
27 |
Correct |
7 ms |
2384 KB |
Output is correct |
28 |
Correct |
7 ms |
2384 KB |
Output is correct |
29 |
Correct |
8 ms |
2552 KB |
Output is correct |
30 |
Correct |
6 ms |
2384 KB |
Output is correct |
31 |
Correct |
6 ms |
2384 KB |
Output is correct |
32 |
Correct |
5 ms |
2384 KB |
Output is correct |
33 |
Correct |
7 ms |
2516 KB |
Output is correct |
34 |
Correct |
8 ms |
2384 KB |
Output is correct |
35 |
Correct |
7 ms |
2384 KB |
Output is correct |
36 |
Correct |
5 ms |
2384 KB |
Output is correct |
37 |
Correct |
26 ms |
2632 KB |
Output is correct |
38 |
Correct |
27 ms |
2584 KB |
Output is correct |
39 |
Correct |
101 ms |
2640 KB |
Output is correct |
40 |
Correct |
62 ms |
2632 KB |
Output is correct |
41 |
Correct |
138 ms |
2776 KB |
Output is correct |
42 |
Correct |
53 ms |
2624 KB |
Output is correct |
43 |
Correct |
89 ms |
2964 KB |
Output is correct |
44 |
Correct |
104 ms |
2968 KB |
Output is correct |
45 |
Correct |
94 ms |
2888 KB |
Output is correct |
46 |
Correct |
81 ms |
2524 KB |
Output is correct |
47 |
Correct |
63 ms |
2640 KB |
Output is correct |
48 |
Correct |
101 ms |
2984 KB |
Output is correct |
49 |
Correct |
108 ms |
2640 KB |
Output is correct |
50 |
Correct |
56 ms |
2640 KB |
Output is correct |
51 |
Correct |
10 ms |
2384 KB |
Output is correct |
52 |
Correct |
126 ms |
3076 KB |
Output is correct |
53 |
Correct |
98 ms |
2892 KB |
Output is correct |
54 |
Correct |
128 ms |
2888 KB |
Output is correct |
55 |
Correct |
283 ms |
3496 KB |
Output is correct |
56 |
Correct |
113 ms |
2888 KB |
Output is correct |
57 |
Correct |
288 ms |
3532 KB |
Output is correct |
58 |
Correct |
144 ms |
3144 KB |
Output is correct |
59 |
Correct |
183 ms |
3276 KB |
Output is correct |
60 |
Correct |
25 ms |
2552 KB |
Output is correct |
61 |
Correct |
205 ms |
3212 KB |
Output is correct |
62 |
Correct |
199 ms |
3276 KB |
Output is correct |
63 |
Correct |
222 ms |
3276 KB |
Output is correct |
64 |
Correct |
213 ms |
3496 KB |
Output is correct |
65 |
Correct |
102 ms |
2640 KB |
Output is correct |
66 |
Correct |
108 ms |
2768 KB |
Output is correct |
67 |
Correct |
199 ms |
3276 KB |
Output is correct |
68 |
Correct |
72 ms |
2636 KB |
Output is correct |
69 |
Correct |
721 ms |
4296 KB |
Output is correct |
70 |
Correct |
443 ms |
3532 KB |
Output is correct |
71 |
Correct |
420 ms |
3532 KB |
Output is correct |
72 |
Correct |
425 ms |
2984 KB |
Output is correct |
73 |
Correct |
418 ms |
2980 KB |
Output is correct |
74 |
Correct |
743 ms |
4408 KB |
Output is correct |
75 |
Correct |
573 ms |
4068 KB |
Output is correct |
76 |
Correct |
806 ms |
4816 KB |
Output is correct |
77 |
Correct |
794 ms |
4552 KB |
Output is correct |