#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 5e2 + 5;
const int NN = N * N;
#define pb push_back
#define sz size()
#define ff first
#define ss second
int sum, n, dp[NN], san[NN], a[N];
vector <int> jog;
int main () {
// freopen("input.txt", "r", stdin);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}
dp[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = sum - a[i]; j >= 0; j--) {
if (dp[j]) {
dp[j + a[i]] += dp[j];
}
}
}
if (sum % 2 == 1 or !dp[sum / 2]) return cout << "0", 0;
for (int i = 1; i <= n; ++i) {
for (int j = a[i]; j <= sum; ++j) {
dp[j] -= dp[j - a[i]];
}
for (int j = 0; j <= sum; ++j) {
// optimization etmeli
int x = sum - a[i] + j;
if (x % 2 == 0 and x / 2 - j >= 0 and dp[x / 2 - j]) {
san[j]++;
}
}
for (int j = sum - a[i]; j >= 0; j--) {
dp[j + a[i]] += dp[j];
}
}
for (int i = 0; i <= sum; ++i) {
if (san[i] == n) {
jog.pb (i);
}
}
cout << (int)jog.sz << endl;
for (int i : jog) {
cout << i << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
444 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
528 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
532 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
444 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
528 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
532 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
15 ms |
604 KB |
Output is correct |
38 |
Correct |
13 ms |
604 KB |
Output is correct |
39 |
Correct |
39 ms |
908 KB |
Output is correct |
40 |
Correct |
24 ms |
860 KB |
Output is correct |
41 |
Correct |
51 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
37 ms |
1132 KB |
Output is correct |
44 |
Correct |
39 ms |
1108 KB |
Output is correct |
45 |
Correct |
39 ms |
1124 KB |
Output is correct |
46 |
Correct |
24 ms |
800 KB |
Output is correct |
47 |
Correct |
22 ms |
708 KB |
Output is correct |
48 |
Correct |
44 ms |
1360 KB |
Output is correct |
49 |
Correct |
44 ms |
856 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
348 KB |
Output is correct |
52 |
Correct |
53 ms |
1248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
444 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
528 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
532 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
15 ms |
604 KB |
Output is correct |
38 |
Correct |
13 ms |
604 KB |
Output is correct |
39 |
Correct |
39 ms |
908 KB |
Output is correct |
40 |
Correct |
24 ms |
860 KB |
Output is correct |
41 |
Correct |
51 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
37 ms |
1132 KB |
Output is correct |
44 |
Correct |
39 ms |
1108 KB |
Output is correct |
45 |
Correct |
39 ms |
1124 KB |
Output is correct |
46 |
Correct |
24 ms |
800 KB |
Output is correct |
47 |
Correct |
22 ms |
708 KB |
Output is correct |
48 |
Correct |
44 ms |
1360 KB |
Output is correct |
49 |
Correct |
44 ms |
856 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
348 KB |
Output is correct |
52 |
Correct |
53 ms |
1248 KB |
Output is correct |
53 |
Correct |
37 ms |
968 KB |
Output is correct |
54 |
Correct |
55 ms |
1360 KB |
Output is correct |
55 |
Correct |
105 ms |
1676 KB |
Output is correct |
56 |
Correct |
49 ms |
1112 KB |
Output is correct |
57 |
Correct |
111 ms |
1996 KB |
Output is correct |
58 |
Correct |
80 ms |
1364 KB |
Output is correct |
59 |
Correct |
72 ms |
1420 KB |
Output is correct |
60 |
Correct |
14 ms |
600 KB |
Output is correct |
61 |
Correct |
85 ms |
1580 KB |
Output is correct |
62 |
Correct |
84 ms |
1560 KB |
Output is correct |
63 |
Correct |
99 ms |
1620 KB |
Output is correct |
64 |
Correct |
88 ms |
1608 KB |
Output is correct |
65 |
Correct |
41 ms |
600 KB |
Output is correct |
66 |
Correct |
58 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
444 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
444 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
528 KB |
Output is correct |
27 |
Correct |
3 ms |
344 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
532 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
15 ms |
604 KB |
Output is correct |
38 |
Correct |
13 ms |
604 KB |
Output is correct |
39 |
Correct |
39 ms |
908 KB |
Output is correct |
40 |
Correct |
24 ms |
860 KB |
Output is correct |
41 |
Correct |
51 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
37 ms |
1132 KB |
Output is correct |
44 |
Correct |
39 ms |
1108 KB |
Output is correct |
45 |
Correct |
39 ms |
1124 KB |
Output is correct |
46 |
Correct |
24 ms |
800 KB |
Output is correct |
47 |
Correct |
22 ms |
708 KB |
Output is correct |
48 |
Correct |
44 ms |
1360 KB |
Output is correct |
49 |
Correct |
44 ms |
856 KB |
Output is correct |
50 |
Correct |
23 ms |
856 KB |
Output is correct |
51 |
Correct |
5 ms |
348 KB |
Output is correct |
52 |
Correct |
53 ms |
1248 KB |
Output is correct |
53 |
Correct |
37 ms |
968 KB |
Output is correct |
54 |
Correct |
55 ms |
1360 KB |
Output is correct |
55 |
Correct |
105 ms |
1676 KB |
Output is correct |
56 |
Correct |
49 ms |
1112 KB |
Output is correct |
57 |
Correct |
111 ms |
1996 KB |
Output is correct |
58 |
Correct |
80 ms |
1364 KB |
Output is correct |
59 |
Correct |
72 ms |
1420 KB |
Output is correct |
60 |
Correct |
14 ms |
600 KB |
Output is correct |
61 |
Correct |
85 ms |
1580 KB |
Output is correct |
62 |
Correct |
84 ms |
1560 KB |
Output is correct |
63 |
Correct |
99 ms |
1620 KB |
Output is correct |
64 |
Correct |
88 ms |
1608 KB |
Output is correct |
65 |
Correct |
41 ms |
600 KB |
Output is correct |
66 |
Correct |
58 ms |
860 KB |
Output is correct |
67 |
Correct |
85 ms |
1372 KB |
Output is correct |
68 |
Correct |
40 ms |
1104 KB |
Output is correct |
69 |
Correct |
283 ms |
3224 KB |
Output is correct |
70 |
Correct |
190 ms |
2064 KB |
Output is correct |
71 |
Correct |
175 ms |
2256 KB |
Output is correct |
72 |
Correct |
176 ms |
1304 KB |
Output is correct |
73 |
Correct |
159 ms |
1412 KB |
Output is correct |
74 |
Correct |
300 ms |
3468 KB |
Output is correct |
75 |
Correct |
247 ms |
2672 KB |
Output is correct |
76 |
Correct |
334 ms |
3528 KB |
Output is correct |
77 |
Correct |
326 ms |
3528 KB |
Output is correct |