#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
if (san[j] < i - 1) continue;
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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
560 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
3 ms |
348 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 |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
560 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
3 ms |
348 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 |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
12 ms |
600 KB |
Output is correct |
38 |
Correct |
19 ms |
604 KB |
Output is correct |
39 |
Correct |
44 ms |
1108 KB |
Output is correct |
40 |
Correct |
26 ms |
696 KB |
Output is correct |
41 |
Correct |
48 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
41 ms |
1108 KB |
Output is correct |
44 |
Correct |
40 ms |
1132 KB |
Output is correct |
45 |
Correct |
46 ms |
1144 KB |
Output is correct |
46 |
Correct |
22 ms |
604 KB |
Output is correct |
47 |
Correct |
24 ms |
708 KB |
Output is correct |
48 |
Correct |
60 ms |
1160 KB |
Output is correct |
49 |
Correct |
40 ms |
860 KB |
Output is correct |
50 |
Correct |
23 ms |
692 KB |
Output is correct |
51 |
Correct |
7 ms |
344 KB |
Output is correct |
52 |
Correct |
53 ms |
1244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
560 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
3 ms |
348 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 |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
12 ms |
600 KB |
Output is correct |
38 |
Correct |
19 ms |
604 KB |
Output is correct |
39 |
Correct |
44 ms |
1108 KB |
Output is correct |
40 |
Correct |
26 ms |
696 KB |
Output is correct |
41 |
Correct |
48 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
41 ms |
1108 KB |
Output is correct |
44 |
Correct |
40 ms |
1132 KB |
Output is correct |
45 |
Correct |
46 ms |
1144 KB |
Output is correct |
46 |
Correct |
22 ms |
604 KB |
Output is correct |
47 |
Correct |
24 ms |
708 KB |
Output is correct |
48 |
Correct |
60 ms |
1160 KB |
Output is correct |
49 |
Correct |
40 ms |
860 KB |
Output is correct |
50 |
Correct |
23 ms |
692 KB |
Output is correct |
51 |
Correct |
7 ms |
344 KB |
Output is correct |
52 |
Correct |
53 ms |
1244 KB |
Output is correct |
53 |
Correct |
41 ms |
1056 KB |
Output is correct |
54 |
Correct |
54 ms |
1116 KB |
Output is correct |
55 |
Correct |
109 ms |
1672 KB |
Output is correct |
56 |
Correct |
51 ms |
1132 KB |
Output is correct |
57 |
Correct |
118 ms |
1980 KB |
Output is correct |
58 |
Correct |
58 ms |
1320 KB |
Output is correct |
59 |
Correct |
80 ms |
1400 KB |
Output is correct |
60 |
Correct |
18 ms |
600 KB |
Output is correct |
61 |
Correct |
88 ms |
1484 KB |
Output is correct |
62 |
Correct |
89 ms |
1560 KB |
Output is correct |
63 |
Correct |
92 ms |
1628 KB |
Output is correct |
64 |
Correct |
108 ms |
1744 KB |
Output is correct |
65 |
Correct |
38 ms |
808 KB |
Output is correct |
66 |
Correct |
42 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
560 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
5 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
2 ms |
464 KB |
Output is correct |
31 |
Correct |
3 ms |
348 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 |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
12 ms |
600 KB |
Output is correct |
38 |
Correct |
19 ms |
604 KB |
Output is correct |
39 |
Correct |
44 ms |
1108 KB |
Output is correct |
40 |
Correct |
26 ms |
696 KB |
Output is correct |
41 |
Correct |
48 ms |
996 KB |
Output is correct |
42 |
Correct |
21 ms |
860 KB |
Output is correct |
43 |
Correct |
41 ms |
1108 KB |
Output is correct |
44 |
Correct |
40 ms |
1132 KB |
Output is correct |
45 |
Correct |
46 ms |
1144 KB |
Output is correct |
46 |
Correct |
22 ms |
604 KB |
Output is correct |
47 |
Correct |
24 ms |
708 KB |
Output is correct |
48 |
Correct |
60 ms |
1160 KB |
Output is correct |
49 |
Correct |
40 ms |
860 KB |
Output is correct |
50 |
Correct |
23 ms |
692 KB |
Output is correct |
51 |
Correct |
7 ms |
344 KB |
Output is correct |
52 |
Correct |
53 ms |
1244 KB |
Output is correct |
53 |
Correct |
41 ms |
1056 KB |
Output is correct |
54 |
Correct |
54 ms |
1116 KB |
Output is correct |
55 |
Correct |
109 ms |
1672 KB |
Output is correct |
56 |
Correct |
51 ms |
1132 KB |
Output is correct |
57 |
Correct |
118 ms |
1980 KB |
Output is correct |
58 |
Correct |
58 ms |
1320 KB |
Output is correct |
59 |
Correct |
80 ms |
1400 KB |
Output is correct |
60 |
Correct |
18 ms |
600 KB |
Output is correct |
61 |
Correct |
88 ms |
1484 KB |
Output is correct |
62 |
Correct |
89 ms |
1560 KB |
Output is correct |
63 |
Correct |
92 ms |
1628 KB |
Output is correct |
64 |
Correct |
108 ms |
1744 KB |
Output is correct |
65 |
Correct |
38 ms |
808 KB |
Output is correct |
66 |
Correct |
42 ms |
852 KB |
Output is correct |
67 |
Correct |
138 ms |
1508 KB |
Output is correct |
68 |
Correct |
75 ms |
848 KB |
Output is correct |
69 |
Correct |
323 ms |
3220 KB |
Output is correct |
70 |
Correct |
177 ms |
2000 KB |
Output is correct |
71 |
Correct |
213 ms |
2028 KB |
Output is correct |
72 |
Correct |
147 ms |
1404 KB |
Output is correct |
73 |
Correct |
141 ms |
1364 KB |
Output is correct |
74 |
Correct |
341 ms |
3320 KB |
Output is correct |
75 |
Correct |
235 ms |
2764 KB |
Output is correct |
76 |
Correct |
322 ms |
3528 KB |
Output is correct |
77 |
Correct |
317 ms |
3396 KB |
Output is correct |