#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 510;
const int N2 = N * N;
const int PW = 10;
const int VL = (1 << PW);
const int oo = 2e9;
const int K = 11;
const int md = int(1e9) + 7;
vector<int> ans, nw;
int f[N2], a[N], n, pref;
int sum(int x, int y){ return (x + y) % md; }
void BAD(){
cout << 0;
exit(0);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
f[0] = 1;
for (int i = 0; i < n; i++) {
cin >> a[i];
pref += a[i];
for (int j = pref; j >= a[i]; j--)
f[j] = sum(f[j], f[j - a[i]]);
}
if (pref & 1) BAD();
if (f[pref >> 1] == 0) BAD();
ans.clear();
for (int i = 1; i < N2; i++)
ans.PB(i);
for (int i = 0; i < n; i++){
for (int j = a[i]; j <= pref; j++)
f[j] = sum(f[j], md - f[j - a[i]]);
nw.clear();
for (int x : ans){
int sm = pref - a[i] + x;
if (sm & 1) continue;
if (f[sm >> 1] == 0) continue;
nw.PB(x);
}
ans = nw;
for (int j = pref; j >= a[i]; j--)
f[j] = sum(f[j], f[j - a[i]]);
}
cout << sz(ans) << '\n';
for (int x : ans)
cout << x << " ";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
10 |
Correct |
5 ms |
1524 KB |
Output is correct |
11 |
Correct |
5 ms |
1524 KB |
Output is correct |
12 |
Correct |
5 ms |
1520 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1524 KB |
Output is correct |
15 |
Correct |
5 ms |
1524 KB |
Output is correct |
16 |
Correct |
5 ms |
1524 KB |
Output is correct |
17 |
Correct |
5 ms |
1524 KB |
Output is correct |
18 |
Correct |
5 ms |
1520 KB |
Output is correct |
19 |
Correct |
5 ms |
1524 KB |
Output is correct |
20 |
Correct |
5 ms |
1524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
10 |
Correct |
5 ms |
1524 KB |
Output is correct |
11 |
Correct |
5 ms |
1524 KB |
Output is correct |
12 |
Correct |
5 ms |
1520 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1524 KB |
Output is correct |
15 |
Correct |
5 ms |
1524 KB |
Output is correct |
16 |
Correct |
5 ms |
1524 KB |
Output is correct |
17 |
Correct |
5 ms |
1524 KB |
Output is correct |
18 |
Correct |
5 ms |
1520 KB |
Output is correct |
19 |
Correct |
5 ms |
1524 KB |
Output is correct |
20 |
Correct |
5 ms |
1524 KB |
Output is correct |
21 |
Correct |
6 ms |
1520 KB |
Output is correct |
22 |
Correct |
6 ms |
1520 KB |
Output is correct |
23 |
Correct |
6 ms |
1520 KB |
Output is correct |
24 |
Correct |
7 ms |
1524 KB |
Output is correct |
25 |
Correct |
10 ms |
1524 KB |
Output is correct |
26 |
Correct |
10 ms |
1524 KB |
Output is correct |
27 |
Correct |
10 ms |
1524 KB |
Output is correct |
28 |
Correct |
10 ms |
1524 KB |
Output is correct |
29 |
Correct |
10 ms |
1524 KB |
Output is correct |
30 |
Correct |
7 ms |
1520 KB |
Output is correct |
31 |
Correct |
9 ms |
1520 KB |
Output is correct |
32 |
Correct |
8 ms |
1524 KB |
Output is correct |
33 |
Correct |
9 ms |
1524 KB |
Output is correct |
34 |
Correct |
9 ms |
1552 KB |
Output is correct |
35 |
Correct |
10 ms |
1524 KB |
Output is correct |
36 |
Correct |
8 ms |
1652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
10 |
Correct |
5 ms |
1524 KB |
Output is correct |
11 |
Correct |
5 ms |
1524 KB |
Output is correct |
12 |
Correct |
5 ms |
1520 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1524 KB |
Output is correct |
15 |
Correct |
5 ms |
1524 KB |
Output is correct |
16 |
Correct |
5 ms |
1524 KB |
Output is correct |
17 |
Correct |
5 ms |
1524 KB |
Output is correct |
18 |
Correct |
5 ms |
1520 KB |
Output is correct |
19 |
Correct |
5 ms |
1524 KB |
Output is correct |
20 |
Correct |
5 ms |
1524 KB |
Output is correct |
21 |
Correct |
6 ms |
1520 KB |
Output is correct |
22 |
Correct |
6 ms |
1520 KB |
Output is correct |
23 |
Correct |
6 ms |
1520 KB |
Output is correct |
24 |
Correct |
7 ms |
1524 KB |
Output is correct |
25 |
Correct |
10 ms |
1524 KB |
Output is correct |
26 |
Correct |
10 ms |
1524 KB |
Output is correct |
27 |
Correct |
10 ms |
1524 KB |
Output is correct |
28 |
Correct |
10 ms |
1524 KB |
Output is correct |
29 |
Correct |
10 ms |
1524 KB |
Output is correct |
30 |
Correct |
7 ms |
1520 KB |
Output is correct |
31 |
Correct |
9 ms |
1520 KB |
Output is correct |
32 |
Correct |
8 ms |
1524 KB |
Output is correct |
33 |
Correct |
9 ms |
1524 KB |
Output is correct |
34 |
Correct |
9 ms |
1552 KB |
Output is correct |
35 |
Correct |
10 ms |
1524 KB |
Output is correct |
36 |
Correct |
8 ms |
1652 KB |
Output is correct |
37 |
Correct |
29 ms |
1652 KB |
Output is correct |
38 |
Correct |
29 ms |
1652 KB |
Output is correct |
39 |
Correct |
78 ms |
1784 KB |
Output is correct |
40 |
Correct |
59 ms |
1772 KB |
Output is correct |
41 |
Correct |
99 ms |
1780 KB |
Output is correct |
42 |
Correct |
51 ms |
1776 KB |
Output is correct |
43 |
Correct |
88 ms |
2032 KB |
Output is correct |
44 |
Correct |
90 ms |
2032 KB |
Output is correct |
45 |
Correct |
90 ms |
2032 KB |
Output is correct |
46 |
Correct |
45 ms |
1652 KB |
Output is correct |
47 |
Correct |
55 ms |
1652 KB |
Output is correct |
48 |
Correct |
92 ms |
1972 KB |
Output is correct |
49 |
Correct |
82 ms |
1780 KB |
Output is correct |
50 |
Correct |
55 ms |
1652 KB |
Output is correct |
51 |
Correct |
9 ms |
504 KB |
Output is correct |
52 |
Correct |
117 ms |
2116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
10 |
Correct |
5 ms |
1524 KB |
Output is correct |
11 |
Correct |
5 ms |
1524 KB |
Output is correct |
12 |
Correct |
5 ms |
1520 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1524 KB |
Output is correct |
15 |
Correct |
5 ms |
1524 KB |
Output is correct |
16 |
Correct |
5 ms |
1524 KB |
Output is correct |
17 |
Correct |
5 ms |
1524 KB |
Output is correct |
18 |
Correct |
5 ms |
1520 KB |
Output is correct |
19 |
Correct |
5 ms |
1524 KB |
Output is correct |
20 |
Correct |
5 ms |
1524 KB |
Output is correct |
21 |
Correct |
6 ms |
1520 KB |
Output is correct |
22 |
Correct |
6 ms |
1520 KB |
Output is correct |
23 |
Correct |
6 ms |
1520 KB |
Output is correct |
24 |
Correct |
7 ms |
1524 KB |
Output is correct |
25 |
Correct |
10 ms |
1524 KB |
Output is correct |
26 |
Correct |
10 ms |
1524 KB |
Output is correct |
27 |
Correct |
10 ms |
1524 KB |
Output is correct |
28 |
Correct |
10 ms |
1524 KB |
Output is correct |
29 |
Correct |
10 ms |
1524 KB |
Output is correct |
30 |
Correct |
7 ms |
1520 KB |
Output is correct |
31 |
Correct |
9 ms |
1520 KB |
Output is correct |
32 |
Correct |
8 ms |
1524 KB |
Output is correct |
33 |
Correct |
9 ms |
1524 KB |
Output is correct |
34 |
Correct |
9 ms |
1552 KB |
Output is correct |
35 |
Correct |
10 ms |
1524 KB |
Output is correct |
36 |
Correct |
8 ms |
1652 KB |
Output is correct |
37 |
Correct |
29 ms |
1652 KB |
Output is correct |
38 |
Correct |
29 ms |
1652 KB |
Output is correct |
39 |
Correct |
78 ms |
1784 KB |
Output is correct |
40 |
Correct |
59 ms |
1772 KB |
Output is correct |
41 |
Correct |
99 ms |
1780 KB |
Output is correct |
42 |
Correct |
51 ms |
1776 KB |
Output is correct |
43 |
Correct |
88 ms |
2032 KB |
Output is correct |
44 |
Correct |
90 ms |
2032 KB |
Output is correct |
45 |
Correct |
90 ms |
2032 KB |
Output is correct |
46 |
Correct |
45 ms |
1652 KB |
Output is correct |
47 |
Correct |
55 ms |
1652 KB |
Output is correct |
48 |
Correct |
92 ms |
1972 KB |
Output is correct |
49 |
Correct |
82 ms |
1780 KB |
Output is correct |
50 |
Correct |
55 ms |
1652 KB |
Output is correct |
51 |
Correct |
9 ms |
504 KB |
Output is correct |
52 |
Correct |
117 ms |
2116 KB |
Output is correct |
53 |
Correct |
89 ms |
1904 KB |
Output is correct |
54 |
Correct |
123 ms |
2012 KB |
Output is correct |
55 |
Correct |
238 ms |
2640 KB |
Output is correct |
56 |
Correct |
109 ms |
2028 KB |
Output is correct |
57 |
Correct |
250 ms |
2672 KB |
Output is correct |
58 |
Correct |
136 ms |
2032 KB |
Output is correct |
59 |
Correct |
169 ms |
2268 KB |
Output is correct |
60 |
Correct |
21 ms |
504 KB |
Output is correct |
61 |
Correct |
189 ms |
2328 KB |
Output is correct |
62 |
Correct |
192 ms |
2540 KB |
Output is correct |
63 |
Correct |
206 ms |
2536 KB |
Output is correct |
64 |
Correct |
203 ms |
2536 KB |
Output is correct |
65 |
Correct |
78 ms |
1652 KB |
Output is correct |
66 |
Correct |
88 ms |
1788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1528 KB |
Output is correct |
2 |
Correct |
5 ms |
1520 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
1524 KB |
Output is correct |
5 |
Correct |
5 ms |
1520 KB |
Output is correct |
6 |
Correct |
5 ms |
1524 KB |
Output is correct |
7 |
Correct |
5 ms |
1520 KB |
Output is correct |
8 |
Correct |
5 ms |
1524 KB |
Output is correct |
9 |
Correct |
5 ms |
1520 KB |
Output is correct |
10 |
Correct |
5 ms |
1524 KB |
Output is correct |
11 |
Correct |
5 ms |
1524 KB |
Output is correct |
12 |
Correct |
5 ms |
1520 KB |
Output is correct |
13 |
Correct |
5 ms |
1528 KB |
Output is correct |
14 |
Correct |
5 ms |
1524 KB |
Output is correct |
15 |
Correct |
5 ms |
1524 KB |
Output is correct |
16 |
Correct |
5 ms |
1524 KB |
Output is correct |
17 |
Correct |
5 ms |
1524 KB |
Output is correct |
18 |
Correct |
5 ms |
1520 KB |
Output is correct |
19 |
Correct |
5 ms |
1524 KB |
Output is correct |
20 |
Correct |
5 ms |
1524 KB |
Output is correct |
21 |
Correct |
6 ms |
1520 KB |
Output is correct |
22 |
Correct |
6 ms |
1520 KB |
Output is correct |
23 |
Correct |
6 ms |
1520 KB |
Output is correct |
24 |
Correct |
7 ms |
1524 KB |
Output is correct |
25 |
Correct |
10 ms |
1524 KB |
Output is correct |
26 |
Correct |
10 ms |
1524 KB |
Output is correct |
27 |
Correct |
10 ms |
1524 KB |
Output is correct |
28 |
Correct |
10 ms |
1524 KB |
Output is correct |
29 |
Correct |
10 ms |
1524 KB |
Output is correct |
30 |
Correct |
7 ms |
1520 KB |
Output is correct |
31 |
Correct |
9 ms |
1520 KB |
Output is correct |
32 |
Correct |
8 ms |
1524 KB |
Output is correct |
33 |
Correct |
9 ms |
1524 KB |
Output is correct |
34 |
Correct |
9 ms |
1552 KB |
Output is correct |
35 |
Correct |
10 ms |
1524 KB |
Output is correct |
36 |
Correct |
8 ms |
1652 KB |
Output is correct |
37 |
Correct |
29 ms |
1652 KB |
Output is correct |
38 |
Correct |
29 ms |
1652 KB |
Output is correct |
39 |
Correct |
78 ms |
1784 KB |
Output is correct |
40 |
Correct |
59 ms |
1772 KB |
Output is correct |
41 |
Correct |
99 ms |
1780 KB |
Output is correct |
42 |
Correct |
51 ms |
1776 KB |
Output is correct |
43 |
Correct |
88 ms |
2032 KB |
Output is correct |
44 |
Correct |
90 ms |
2032 KB |
Output is correct |
45 |
Correct |
90 ms |
2032 KB |
Output is correct |
46 |
Correct |
45 ms |
1652 KB |
Output is correct |
47 |
Correct |
55 ms |
1652 KB |
Output is correct |
48 |
Correct |
92 ms |
1972 KB |
Output is correct |
49 |
Correct |
82 ms |
1780 KB |
Output is correct |
50 |
Correct |
55 ms |
1652 KB |
Output is correct |
51 |
Correct |
9 ms |
504 KB |
Output is correct |
52 |
Correct |
117 ms |
2116 KB |
Output is correct |
53 |
Correct |
89 ms |
1904 KB |
Output is correct |
54 |
Correct |
123 ms |
2012 KB |
Output is correct |
55 |
Correct |
238 ms |
2640 KB |
Output is correct |
56 |
Correct |
109 ms |
2028 KB |
Output is correct |
57 |
Correct |
250 ms |
2672 KB |
Output is correct |
58 |
Correct |
136 ms |
2032 KB |
Output is correct |
59 |
Correct |
169 ms |
2268 KB |
Output is correct |
60 |
Correct |
21 ms |
504 KB |
Output is correct |
61 |
Correct |
189 ms |
2328 KB |
Output is correct |
62 |
Correct |
192 ms |
2540 KB |
Output is correct |
63 |
Correct |
206 ms |
2536 KB |
Output is correct |
64 |
Correct |
203 ms |
2536 KB |
Output is correct |
65 |
Correct |
78 ms |
1652 KB |
Output is correct |
66 |
Correct |
88 ms |
1788 KB |
Output is correct |
67 |
Correct |
192 ms |
2284 KB |
Output is correct |
68 |
Correct |
58 ms |
760 KB |
Output is correct |
69 |
Correct |
649 ms |
3824 KB |
Output is correct |
70 |
Correct |
400 ms |
2952 KB |
Output is correct |
71 |
Correct |
387 ms |
2860 KB |
Output is correct |
72 |
Correct |
304 ms |
2412 KB |
Output is correct |
73 |
Correct |
303 ms |
2416 KB |
Output is correct |
74 |
Correct |
682 ms |
4020 KB |
Output is correct |
75 |
Correct |
534 ms |
3608 KB |
Output is correct |
76 |
Correct |
725 ms |
4036 KB |
Output is correct |
77 |
Correct |
721 ms |
4096 KB |
Output is correct |