#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define mod 1000000007
ofstream fout(".out");
ifstream fin(".in");
int n;
ll arr[501], dp[250001];
ll sum;
bool ans[250001];
void remove(ll x) {
for(int i = x; i <= sum; i++)
dp[i] = (dp[i] - dp[i - x] + mod) % mod;
}
void add(ll x) {
for(int i = sum; i >= x; i--)
dp[i] = (dp[i] + dp[i - x]) % mod;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
dp[0] = 1;
for(int i = 0; i < n; i++) {
for(int j = sum; j >= arr[i]; j--)
dp[j] = (dp[j] + dp[j - arr[i]]) % mod;
}
if(sum % 2 || !dp[sum / 2]) {
cout << 0;
return 0;
}
for(int i = 1; i <= sum; i++)
ans[i] = 1;
int anss = sum;
for(int i = 0; i < n; i++) {
remove(arr[i]);
for(int j = 1; j <= sum; j++) {
if(!ans[j])
continue;
ll x = sum - arr[i] + j;
if(j > x / 2 || j % 2 != arr[i] % 2 || !dp[(x / 2) - j]) {
ans[j] = 0;
anss--;
}
}
add(arr[i]);
}
cout << anss << "\n";
for(int i = 1; i <= sum; i++) {
if(ans[i])
cout << i << " ";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
380 KB |
Output is correct |
25 |
Correct |
6 ms |
336 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
380 KB |
Output is correct |
25 |
Correct |
6 ms |
336 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
496 KB |
Output is correct |
38 |
Correct |
24 ms |
520 KB |
Output is correct |
39 |
Correct |
83 ms |
868 KB |
Output is correct |
40 |
Correct |
53 ms |
612 KB |
Output is correct |
41 |
Correct |
107 ms |
908 KB |
Output is correct |
42 |
Correct |
44 ms |
600 KB |
Output is correct |
43 |
Correct |
79 ms |
932 KB |
Output is correct |
44 |
Correct |
81 ms |
900 KB |
Output is correct |
45 |
Correct |
87 ms |
948 KB |
Output is correct |
46 |
Correct |
47 ms |
600 KB |
Output is correct |
47 |
Correct |
48 ms |
624 KB |
Output is correct |
48 |
Correct |
87 ms |
868 KB |
Output is correct |
49 |
Correct |
84 ms |
844 KB |
Output is correct |
50 |
Correct |
48 ms |
628 KB |
Output is correct |
51 |
Correct |
14 ms |
468 KB |
Output is correct |
52 |
Correct |
109 ms |
1084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
380 KB |
Output is correct |
25 |
Correct |
6 ms |
336 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
496 KB |
Output is correct |
38 |
Correct |
24 ms |
520 KB |
Output is correct |
39 |
Correct |
83 ms |
868 KB |
Output is correct |
40 |
Correct |
53 ms |
612 KB |
Output is correct |
41 |
Correct |
107 ms |
908 KB |
Output is correct |
42 |
Correct |
44 ms |
600 KB |
Output is correct |
43 |
Correct |
79 ms |
932 KB |
Output is correct |
44 |
Correct |
81 ms |
900 KB |
Output is correct |
45 |
Correct |
87 ms |
948 KB |
Output is correct |
46 |
Correct |
47 ms |
600 KB |
Output is correct |
47 |
Correct |
48 ms |
624 KB |
Output is correct |
48 |
Correct |
87 ms |
868 KB |
Output is correct |
49 |
Correct |
84 ms |
844 KB |
Output is correct |
50 |
Correct |
48 ms |
628 KB |
Output is correct |
51 |
Correct |
14 ms |
468 KB |
Output is correct |
52 |
Correct |
109 ms |
1084 KB |
Output is correct |
53 |
Correct |
81 ms |
856 KB |
Output is correct |
54 |
Correct |
114 ms |
900 KB |
Output is correct |
55 |
Correct |
225 ms |
1560 KB |
Output is correct |
56 |
Correct |
98 ms |
952 KB |
Output is correct |
57 |
Correct |
254 ms |
1608 KB |
Output is correct |
58 |
Correct |
126 ms |
948 KB |
Output is correct |
59 |
Correct |
168 ms |
1188 KB |
Output is correct |
60 |
Correct |
33 ms |
724 KB |
Output is correct |
61 |
Correct |
177 ms |
1260 KB |
Output is correct |
62 |
Correct |
177 ms |
1428 KB |
Output is correct |
63 |
Correct |
190 ms |
1520 KB |
Output is correct |
64 |
Correct |
195 ms |
1516 KB |
Output is correct |
65 |
Correct |
85 ms |
724 KB |
Output is correct |
66 |
Correct |
95 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
380 KB |
Output is correct |
25 |
Correct |
6 ms |
336 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
6 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
4 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
6 ms |
340 KB |
Output is correct |
35 |
Correct |
6 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
340 KB |
Output is correct |
37 |
Correct |
24 ms |
496 KB |
Output is correct |
38 |
Correct |
24 ms |
520 KB |
Output is correct |
39 |
Correct |
83 ms |
868 KB |
Output is correct |
40 |
Correct |
53 ms |
612 KB |
Output is correct |
41 |
Correct |
107 ms |
908 KB |
Output is correct |
42 |
Correct |
44 ms |
600 KB |
Output is correct |
43 |
Correct |
79 ms |
932 KB |
Output is correct |
44 |
Correct |
81 ms |
900 KB |
Output is correct |
45 |
Correct |
87 ms |
948 KB |
Output is correct |
46 |
Correct |
47 ms |
600 KB |
Output is correct |
47 |
Correct |
48 ms |
624 KB |
Output is correct |
48 |
Correct |
87 ms |
868 KB |
Output is correct |
49 |
Correct |
84 ms |
844 KB |
Output is correct |
50 |
Correct |
48 ms |
628 KB |
Output is correct |
51 |
Correct |
14 ms |
468 KB |
Output is correct |
52 |
Correct |
109 ms |
1084 KB |
Output is correct |
53 |
Correct |
81 ms |
856 KB |
Output is correct |
54 |
Correct |
114 ms |
900 KB |
Output is correct |
55 |
Correct |
225 ms |
1560 KB |
Output is correct |
56 |
Correct |
98 ms |
952 KB |
Output is correct |
57 |
Correct |
254 ms |
1608 KB |
Output is correct |
58 |
Correct |
126 ms |
948 KB |
Output is correct |
59 |
Correct |
168 ms |
1188 KB |
Output is correct |
60 |
Correct |
33 ms |
724 KB |
Output is correct |
61 |
Correct |
177 ms |
1260 KB |
Output is correct |
62 |
Correct |
177 ms |
1428 KB |
Output is correct |
63 |
Correct |
190 ms |
1520 KB |
Output is correct |
64 |
Correct |
195 ms |
1516 KB |
Output is correct |
65 |
Correct |
85 ms |
724 KB |
Output is correct |
66 |
Correct |
95 ms |
800 KB |
Output is correct |
67 |
Correct |
200 ms |
1208 KB |
Output is correct |
68 |
Correct |
105 ms |
1296 KB |
Output is correct |
69 |
Correct |
608 ms |
2832 KB |
Output is correct |
70 |
Correct |
379 ms |
1844 KB |
Output is correct |
71 |
Correct |
354 ms |
1692 KB |
Output is correct |
72 |
Correct |
333 ms |
1356 KB |
Output is correct |
73 |
Correct |
357 ms |
1308 KB |
Output is correct |
74 |
Correct |
652 ms |
2980 KB |
Output is correct |
75 |
Correct |
505 ms |
2380 KB |
Output is correct |
76 |
Correct |
697 ms |
3120 KB |
Output is correct |
77 |
Correct |
692 ms |
3056 KB |
Output is correct |