#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500 * 500 + 7;
const int mod = 1e9 + 7;
int dp[N];
int can[N];
void add(int x) {
for (int i = N - x - 1; i >= 0; i--) {
dp[i + x] = (dp[i + x] + dp[i]) % mod;
}
}
void rem(int x) {
for (int i = x; i < N; i++) {
dp[i] = (dp[i] - dp[i - x] + mod) % mod;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 1;
int sum = 0;
for (int i = 0; i < n; i++) {
add(a[i]);
sum += a[i];
}
if (!dp[sum / 2]) {
cout << 0 << '\n';
return 0;
}
for (int i = 0; i < n; i++) {
sum -= a[i];
rem(a[i]);
for (int j = 0; j < N; j++) {
if (dp[j]) {
can[abs(sum - 2 * j)]++;
}
}
sum += a[i];
add(a[i]);
}
vector <int> res;
for (int i = 1; i < N; i++) {
if (can[i] == 2 * n) {
res.push_back(i);
}
}
cout << (int) res.size() << '\n';
for (int x : res) {
cout << x << ' ';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
10 |
Correct |
54 ms |
1400 KB |
Output is correct |
11 |
Correct |
59 ms |
1272 KB |
Output is correct |
12 |
Correct |
54 ms |
1276 KB |
Output is correct |
13 |
Correct |
49 ms |
1400 KB |
Output is correct |
14 |
Correct |
52 ms |
1368 KB |
Output is correct |
15 |
Correct |
56 ms |
1372 KB |
Output is correct |
16 |
Correct |
60 ms |
1276 KB |
Output is correct |
17 |
Correct |
35 ms |
1400 KB |
Output is correct |
18 |
Correct |
45 ms |
1272 KB |
Output is correct |
19 |
Correct |
49 ms |
1372 KB |
Output is correct |
20 |
Correct |
53 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
10 |
Correct |
54 ms |
1400 KB |
Output is correct |
11 |
Correct |
59 ms |
1272 KB |
Output is correct |
12 |
Correct |
54 ms |
1276 KB |
Output is correct |
13 |
Correct |
49 ms |
1400 KB |
Output is correct |
14 |
Correct |
52 ms |
1368 KB |
Output is correct |
15 |
Correct |
56 ms |
1372 KB |
Output is correct |
16 |
Correct |
60 ms |
1276 KB |
Output is correct |
17 |
Correct |
35 ms |
1400 KB |
Output is correct |
18 |
Correct |
45 ms |
1272 KB |
Output is correct |
19 |
Correct |
49 ms |
1372 KB |
Output is correct |
20 |
Correct |
53 ms |
1364 KB |
Output is correct |
21 |
Correct |
111 ms |
1380 KB |
Output is correct |
22 |
Correct |
127 ms |
1500 KB |
Output is correct |
23 |
Correct |
89 ms |
1460 KB |
Output is correct |
24 |
Correct |
162 ms |
1400 KB |
Output is correct |
25 |
Correct |
160 ms |
1400 KB |
Output is correct |
26 |
Correct |
169 ms |
1400 KB |
Output is correct |
27 |
Correct |
168 ms |
1400 KB |
Output is correct |
28 |
Correct |
167 ms |
1400 KB |
Output is correct |
29 |
Correct |
168 ms |
1440 KB |
Output is correct |
30 |
Correct |
168 ms |
1400 KB |
Output is correct |
31 |
Correct |
168 ms |
1404 KB |
Output is correct |
32 |
Correct |
170 ms |
1388 KB |
Output is correct |
33 |
Correct |
168 ms |
1528 KB |
Output is correct |
34 |
Correct |
167 ms |
1444 KB |
Output is correct |
35 |
Correct |
168 ms |
1440 KB |
Output is correct |
36 |
Correct |
172 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
10 |
Correct |
54 ms |
1400 KB |
Output is correct |
11 |
Correct |
59 ms |
1272 KB |
Output is correct |
12 |
Correct |
54 ms |
1276 KB |
Output is correct |
13 |
Correct |
49 ms |
1400 KB |
Output is correct |
14 |
Correct |
52 ms |
1368 KB |
Output is correct |
15 |
Correct |
56 ms |
1372 KB |
Output is correct |
16 |
Correct |
60 ms |
1276 KB |
Output is correct |
17 |
Correct |
35 ms |
1400 KB |
Output is correct |
18 |
Correct |
45 ms |
1272 KB |
Output is correct |
19 |
Correct |
49 ms |
1372 KB |
Output is correct |
20 |
Correct |
53 ms |
1364 KB |
Output is correct |
21 |
Correct |
111 ms |
1380 KB |
Output is correct |
22 |
Correct |
127 ms |
1500 KB |
Output is correct |
23 |
Correct |
89 ms |
1460 KB |
Output is correct |
24 |
Correct |
162 ms |
1400 KB |
Output is correct |
25 |
Correct |
160 ms |
1400 KB |
Output is correct |
26 |
Correct |
169 ms |
1400 KB |
Output is correct |
27 |
Correct |
168 ms |
1400 KB |
Output is correct |
28 |
Correct |
167 ms |
1400 KB |
Output is correct |
29 |
Correct |
168 ms |
1440 KB |
Output is correct |
30 |
Correct |
168 ms |
1400 KB |
Output is correct |
31 |
Correct |
168 ms |
1404 KB |
Output is correct |
32 |
Correct |
170 ms |
1388 KB |
Output is correct |
33 |
Correct |
168 ms |
1528 KB |
Output is correct |
34 |
Correct |
167 ms |
1444 KB |
Output is correct |
35 |
Correct |
168 ms |
1440 KB |
Output is correct |
36 |
Correct |
172 ms |
1528 KB |
Output is correct |
37 |
Correct |
335 ms |
1492 KB |
Output is correct |
38 |
Correct |
336 ms |
1580 KB |
Output is correct |
39 |
Correct |
409 ms |
1628 KB |
Output is correct |
40 |
Correct |
458 ms |
1624 KB |
Output is correct |
41 |
Correct |
448 ms |
1784 KB |
Output is correct |
42 |
Correct |
423 ms |
1656 KB |
Output is correct |
43 |
Correct |
418 ms |
2040 KB |
Output is correct |
44 |
Correct |
425 ms |
2012 KB |
Output is correct |
45 |
Correct |
432 ms |
1908 KB |
Output is correct |
46 |
Correct |
450 ms |
1528 KB |
Output is correct |
47 |
Correct |
425 ms |
1688 KB |
Output is correct |
48 |
Correct |
427 ms |
1916 KB |
Output is correct |
49 |
Correct |
422 ms |
1612 KB |
Output is correct |
50 |
Correct |
427 ms |
1628 KB |
Output is correct |
51 |
Correct |
423 ms |
1624 KB |
Output is correct |
52 |
Correct |
466 ms |
2056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
10 |
Correct |
54 ms |
1400 KB |
Output is correct |
11 |
Correct |
59 ms |
1272 KB |
Output is correct |
12 |
Correct |
54 ms |
1276 KB |
Output is correct |
13 |
Correct |
49 ms |
1400 KB |
Output is correct |
14 |
Correct |
52 ms |
1368 KB |
Output is correct |
15 |
Correct |
56 ms |
1372 KB |
Output is correct |
16 |
Correct |
60 ms |
1276 KB |
Output is correct |
17 |
Correct |
35 ms |
1400 KB |
Output is correct |
18 |
Correct |
45 ms |
1272 KB |
Output is correct |
19 |
Correct |
49 ms |
1372 KB |
Output is correct |
20 |
Correct |
53 ms |
1364 KB |
Output is correct |
21 |
Correct |
111 ms |
1380 KB |
Output is correct |
22 |
Correct |
127 ms |
1500 KB |
Output is correct |
23 |
Correct |
89 ms |
1460 KB |
Output is correct |
24 |
Correct |
162 ms |
1400 KB |
Output is correct |
25 |
Correct |
160 ms |
1400 KB |
Output is correct |
26 |
Correct |
169 ms |
1400 KB |
Output is correct |
27 |
Correct |
168 ms |
1400 KB |
Output is correct |
28 |
Correct |
167 ms |
1400 KB |
Output is correct |
29 |
Correct |
168 ms |
1440 KB |
Output is correct |
30 |
Correct |
168 ms |
1400 KB |
Output is correct |
31 |
Correct |
168 ms |
1404 KB |
Output is correct |
32 |
Correct |
170 ms |
1388 KB |
Output is correct |
33 |
Correct |
168 ms |
1528 KB |
Output is correct |
34 |
Correct |
167 ms |
1444 KB |
Output is correct |
35 |
Correct |
168 ms |
1440 KB |
Output is correct |
36 |
Correct |
172 ms |
1528 KB |
Output is correct |
37 |
Correct |
335 ms |
1492 KB |
Output is correct |
38 |
Correct |
336 ms |
1580 KB |
Output is correct |
39 |
Correct |
409 ms |
1628 KB |
Output is correct |
40 |
Correct |
458 ms |
1624 KB |
Output is correct |
41 |
Correct |
448 ms |
1784 KB |
Output is correct |
42 |
Correct |
423 ms |
1656 KB |
Output is correct |
43 |
Correct |
418 ms |
2040 KB |
Output is correct |
44 |
Correct |
425 ms |
2012 KB |
Output is correct |
45 |
Correct |
432 ms |
1908 KB |
Output is correct |
46 |
Correct |
450 ms |
1528 KB |
Output is correct |
47 |
Correct |
425 ms |
1688 KB |
Output is correct |
48 |
Correct |
427 ms |
1916 KB |
Output is correct |
49 |
Correct |
422 ms |
1612 KB |
Output is correct |
50 |
Correct |
427 ms |
1628 KB |
Output is correct |
51 |
Correct |
423 ms |
1624 KB |
Output is correct |
52 |
Correct |
466 ms |
2056 KB |
Output is correct |
53 |
Correct |
511 ms |
1884 KB |
Output is correct |
54 |
Correct |
598 ms |
1912 KB |
Output is correct |
55 |
Correct |
620 ms |
2396 KB |
Output is correct |
56 |
Correct |
524 ms |
1912 KB |
Output is correct |
57 |
Correct |
620 ms |
2552 KB |
Output is correct |
58 |
Correct |
602 ms |
2040 KB |
Output is correct |
59 |
Correct |
609 ms |
2296 KB |
Output is correct |
60 |
Correct |
600 ms |
1528 KB |
Output is correct |
61 |
Correct |
610 ms |
2168 KB |
Output is correct |
62 |
Correct |
563 ms |
2296 KB |
Output is correct |
63 |
Correct |
583 ms |
2420 KB |
Output is correct |
64 |
Correct |
554 ms |
2424 KB |
Output is correct |
65 |
Correct |
525 ms |
1528 KB |
Output is correct |
66 |
Correct |
512 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1276 KB |
Output is correct |
2 |
Correct |
14 ms |
1400 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
11 ms |
1400 KB |
Output is correct |
5 |
Correct |
24 ms |
1400 KB |
Output is correct |
6 |
Correct |
18 ms |
1400 KB |
Output is correct |
7 |
Correct |
14 ms |
1400 KB |
Output is correct |
8 |
Correct |
24 ms |
1400 KB |
Output is correct |
9 |
Correct |
20 ms |
1272 KB |
Output is correct |
10 |
Correct |
54 ms |
1400 KB |
Output is correct |
11 |
Correct |
59 ms |
1272 KB |
Output is correct |
12 |
Correct |
54 ms |
1276 KB |
Output is correct |
13 |
Correct |
49 ms |
1400 KB |
Output is correct |
14 |
Correct |
52 ms |
1368 KB |
Output is correct |
15 |
Correct |
56 ms |
1372 KB |
Output is correct |
16 |
Correct |
60 ms |
1276 KB |
Output is correct |
17 |
Correct |
35 ms |
1400 KB |
Output is correct |
18 |
Correct |
45 ms |
1272 KB |
Output is correct |
19 |
Correct |
49 ms |
1372 KB |
Output is correct |
20 |
Correct |
53 ms |
1364 KB |
Output is correct |
21 |
Correct |
111 ms |
1380 KB |
Output is correct |
22 |
Correct |
127 ms |
1500 KB |
Output is correct |
23 |
Correct |
89 ms |
1460 KB |
Output is correct |
24 |
Correct |
162 ms |
1400 KB |
Output is correct |
25 |
Correct |
160 ms |
1400 KB |
Output is correct |
26 |
Correct |
169 ms |
1400 KB |
Output is correct |
27 |
Correct |
168 ms |
1400 KB |
Output is correct |
28 |
Correct |
167 ms |
1400 KB |
Output is correct |
29 |
Correct |
168 ms |
1440 KB |
Output is correct |
30 |
Correct |
168 ms |
1400 KB |
Output is correct |
31 |
Correct |
168 ms |
1404 KB |
Output is correct |
32 |
Correct |
170 ms |
1388 KB |
Output is correct |
33 |
Correct |
168 ms |
1528 KB |
Output is correct |
34 |
Correct |
167 ms |
1444 KB |
Output is correct |
35 |
Correct |
168 ms |
1440 KB |
Output is correct |
36 |
Correct |
172 ms |
1528 KB |
Output is correct |
37 |
Correct |
335 ms |
1492 KB |
Output is correct |
38 |
Correct |
336 ms |
1580 KB |
Output is correct |
39 |
Correct |
409 ms |
1628 KB |
Output is correct |
40 |
Correct |
458 ms |
1624 KB |
Output is correct |
41 |
Correct |
448 ms |
1784 KB |
Output is correct |
42 |
Correct |
423 ms |
1656 KB |
Output is correct |
43 |
Correct |
418 ms |
2040 KB |
Output is correct |
44 |
Correct |
425 ms |
2012 KB |
Output is correct |
45 |
Correct |
432 ms |
1908 KB |
Output is correct |
46 |
Correct |
450 ms |
1528 KB |
Output is correct |
47 |
Correct |
425 ms |
1688 KB |
Output is correct |
48 |
Correct |
427 ms |
1916 KB |
Output is correct |
49 |
Correct |
422 ms |
1612 KB |
Output is correct |
50 |
Correct |
427 ms |
1628 KB |
Output is correct |
51 |
Correct |
423 ms |
1624 KB |
Output is correct |
52 |
Correct |
466 ms |
2056 KB |
Output is correct |
53 |
Correct |
511 ms |
1884 KB |
Output is correct |
54 |
Correct |
598 ms |
1912 KB |
Output is correct |
55 |
Correct |
620 ms |
2396 KB |
Output is correct |
56 |
Correct |
524 ms |
1912 KB |
Output is correct |
57 |
Correct |
620 ms |
2552 KB |
Output is correct |
58 |
Correct |
602 ms |
2040 KB |
Output is correct |
59 |
Correct |
609 ms |
2296 KB |
Output is correct |
60 |
Correct |
600 ms |
1528 KB |
Output is correct |
61 |
Correct |
610 ms |
2168 KB |
Output is correct |
62 |
Correct |
563 ms |
2296 KB |
Output is correct |
63 |
Correct |
583 ms |
2420 KB |
Output is correct |
64 |
Correct |
554 ms |
2424 KB |
Output is correct |
65 |
Correct |
525 ms |
1528 KB |
Output is correct |
66 |
Correct |
512 ms |
1628 KB |
Output is correct |
67 |
Correct |
698 ms |
2260 KB |
Output is correct |
68 |
Correct |
234 ms |
1272 KB |
Output is correct |
69 |
Correct |
945 ms |
3356 KB |
Output is correct |
70 |
Correct |
901 ms |
2552 KB |
Output is correct |
71 |
Correct |
892 ms |
2556 KB |
Output is correct |
72 |
Correct |
891 ms |
1784 KB |
Output is correct |
73 |
Correct |
885 ms |
1784 KB |
Output is correct |
74 |
Correct |
945 ms |
3572 KB |
Output is correct |
75 |
Correct |
917 ms |
3164 KB |
Output is correct |
76 |
Correct |
955 ms |
3572 KB |
Output is correct |
77 |
Correct |
956 ms |
3828 KB |
Output is correct |