#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 5e2 + 5;
const ll shift = 2e6;
const ll mod = 1e9 + 7;
const ll M = 2e5 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll block = 500;
const double eps = 1e-10;
ll n, a[N], dp[M], acc = 0, cnt[M];
int main(){
speed;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
acc += a[i];
}
dp[0] = 1;
for(int i = 1; i <= n; i++){
for(int sum = M - 5; sum >= a[i]; sum--){
dp[sum] += dp[sum - a[i]];
}
}
if(acc % 2 != 0 || dp[acc / 2] == 0){
cout << 0 << endl;
return 0;
}
for(int i = 1; i <= n; i++){
for(int sum = a[i]; sum <= M - 5; sum++){
dp[sum] -= dp[sum - a[i]];
}
acc -= a[i];
for(int sum = 0; sum <= M - 5; sum++){
if(dp[sum]){
int ost = acc - sum;
if(ost - sum < 0)
continue;
cnt[ost - sum]++;
}
}
acc += a[i];
for(int sum = M - 5; sum >= a[i]; sum--){
dp[sum] += dp[sum - a[i]];
}
}
vector <int> ans;
for(int i = 0; i <= M - 5; i++){
if(cnt[i] == n)
ans.pb(i);
}
cout << ans.size() << endl;
for(auto to : ans)
cout << to << " ";
}
/*
%I64d
%I64d
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
10 |
Correct |
15 ms |
1868 KB |
Output is correct |
11 |
Correct |
17 ms |
1884 KB |
Output is correct |
12 |
Correct |
15 ms |
1888 KB |
Output is correct |
13 |
Correct |
13 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
23 ms |
1884 KB |
Output is correct |
17 |
Correct |
12 ms |
1884 KB |
Output is correct |
18 |
Correct |
16 ms |
1868 KB |
Output is correct |
19 |
Correct |
16 ms |
1888 KB |
Output is correct |
20 |
Correct |
15 ms |
1896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
10 |
Correct |
15 ms |
1868 KB |
Output is correct |
11 |
Correct |
17 ms |
1884 KB |
Output is correct |
12 |
Correct |
15 ms |
1888 KB |
Output is correct |
13 |
Correct |
13 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
23 ms |
1884 KB |
Output is correct |
17 |
Correct |
12 ms |
1884 KB |
Output is correct |
18 |
Correct |
16 ms |
1868 KB |
Output is correct |
19 |
Correct |
16 ms |
1888 KB |
Output is correct |
20 |
Correct |
15 ms |
1896 KB |
Output is correct |
21 |
Correct |
29 ms |
1892 KB |
Output is correct |
22 |
Correct |
34 ms |
1924 KB |
Output is correct |
23 |
Correct |
32 ms |
1868 KB |
Output is correct |
24 |
Correct |
47 ms |
1908 KB |
Output is correct |
25 |
Correct |
52 ms |
1976 KB |
Output is correct |
26 |
Correct |
48 ms |
1892 KB |
Output is correct |
27 |
Correct |
49 ms |
1996 KB |
Output is correct |
28 |
Correct |
49 ms |
1944 KB |
Output is correct |
29 |
Correct |
46 ms |
1948 KB |
Output is correct |
30 |
Correct |
47 ms |
1896 KB |
Output is correct |
31 |
Correct |
47 ms |
1868 KB |
Output is correct |
32 |
Correct |
53 ms |
1908 KB |
Output is correct |
33 |
Correct |
47 ms |
1892 KB |
Output is correct |
34 |
Correct |
49 ms |
1948 KB |
Output is correct |
35 |
Correct |
45 ms |
1868 KB |
Output is correct |
36 |
Correct |
47 ms |
1920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
10 |
Correct |
15 ms |
1868 KB |
Output is correct |
11 |
Correct |
17 ms |
1884 KB |
Output is correct |
12 |
Correct |
15 ms |
1888 KB |
Output is correct |
13 |
Correct |
13 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
23 ms |
1884 KB |
Output is correct |
17 |
Correct |
12 ms |
1884 KB |
Output is correct |
18 |
Correct |
16 ms |
1868 KB |
Output is correct |
19 |
Correct |
16 ms |
1888 KB |
Output is correct |
20 |
Correct |
15 ms |
1896 KB |
Output is correct |
21 |
Correct |
29 ms |
1892 KB |
Output is correct |
22 |
Correct |
34 ms |
1924 KB |
Output is correct |
23 |
Correct |
32 ms |
1868 KB |
Output is correct |
24 |
Correct |
47 ms |
1908 KB |
Output is correct |
25 |
Correct |
52 ms |
1976 KB |
Output is correct |
26 |
Correct |
48 ms |
1892 KB |
Output is correct |
27 |
Correct |
49 ms |
1996 KB |
Output is correct |
28 |
Correct |
49 ms |
1944 KB |
Output is correct |
29 |
Correct |
46 ms |
1948 KB |
Output is correct |
30 |
Correct |
47 ms |
1896 KB |
Output is correct |
31 |
Correct |
47 ms |
1868 KB |
Output is correct |
32 |
Correct |
53 ms |
1908 KB |
Output is correct |
33 |
Correct |
47 ms |
1892 KB |
Output is correct |
34 |
Correct |
49 ms |
1948 KB |
Output is correct |
35 |
Correct |
45 ms |
1868 KB |
Output is correct |
36 |
Correct |
47 ms |
1920 KB |
Output is correct |
37 |
Correct |
105 ms |
2148 KB |
Output is correct |
38 |
Correct |
93 ms |
2132 KB |
Output is correct |
39 |
Correct |
120 ms |
2352 KB |
Output is correct |
40 |
Correct |
124 ms |
2252 KB |
Output is correct |
41 |
Correct |
137 ms |
2372 KB |
Output is correct |
42 |
Correct |
114 ms |
2240 KB |
Output is correct |
43 |
Correct |
114 ms |
2684 KB |
Output is correct |
44 |
Correct |
113 ms |
2620 KB |
Output is correct |
45 |
Correct |
123 ms |
2648 KB |
Output is correct |
46 |
Correct |
121 ms |
2020 KB |
Output is correct |
47 |
Correct |
115 ms |
2248 KB |
Output is correct |
48 |
Correct |
117 ms |
2660 KB |
Output is correct |
49 |
Correct |
126 ms |
2396 KB |
Output is correct |
50 |
Correct |
113 ms |
2252 KB |
Output is correct |
51 |
Correct |
25 ms |
1868 KB |
Output is correct |
52 |
Correct |
138 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
10 |
Correct |
15 ms |
1868 KB |
Output is correct |
11 |
Correct |
17 ms |
1884 KB |
Output is correct |
12 |
Correct |
15 ms |
1888 KB |
Output is correct |
13 |
Correct |
13 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
23 ms |
1884 KB |
Output is correct |
17 |
Correct |
12 ms |
1884 KB |
Output is correct |
18 |
Correct |
16 ms |
1868 KB |
Output is correct |
19 |
Correct |
16 ms |
1888 KB |
Output is correct |
20 |
Correct |
15 ms |
1896 KB |
Output is correct |
21 |
Correct |
29 ms |
1892 KB |
Output is correct |
22 |
Correct |
34 ms |
1924 KB |
Output is correct |
23 |
Correct |
32 ms |
1868 KB |
Output is correct |
24 |
Correct |
47 ms |
1908 KB |
Output is correct |
25 |
Correct |
52 ms |
1976 KB |
Output is correct |
26 |
Correct |
48 ms |
1892 KB |
Output is correct |
27 |
Correct |
49 ms |
1996 KB |
Output is correct |
28 |
Correct |
49 ms |
1944 KB |
Output is correct |
29 |
Correct |
46 ms |
1948 KB |
Output is correct |
30 |
Correct |
47 ms |
1896 KB |
Output is correct |
31 |
Correct |
47 ms |
1868 KB |
Output is correct |
32 |
Correct |
53 ms |
1908 KB |
Output is correct |
33 |
Correct |
47 ms |
1892 KB |
Output is correct |
34 |
Correct |
49 ms |
1948 KB |
Output is correct |
35 |
Correct |
45 ms |
1868 KB |
Output is correct |
36 |
Correct |
47 ms |
1920 KB |
Output is correct |
37 |
Correct |
105 ms |
2148 KB |
Output is correct |
38 |
Correct |
93 ms |
2132 KB |
Output is correct |
39 |
Correct |
120 ms |
2352 KB |
Output is correct |
40 |
Correct |
124 ms |
2252 KB |
Output is correct |
41 |
Correct |
137 ms |
2372 KB |
Output is correct |
42 |
Correct |
114 ms |
2240 KB |
Output is correct |
43 |
Correct |
114 ms |
2684 KB |
Output is correct |
44 |
Correct |
113 ms |
2620 KB |
Output is correct |
45 |
Correct |
123 ms |
2648 KB |
Output is correct |
46 |
Correct |
121 ms |
2020 KB |
Output is correct |
47 |
Correct |
115 ms |
2248 KB |
Output is correct |
48 |
Correct |
117 ms |
2660 KB |
Output is correct |
49 |
Correct |
126 ms |
2396 KB |
Output is correct |
50 |
Correct |
113 ms |
2252 KB |
Output is correct |
51 |
Correct |
25 ms |
1868 KB |
Output is correct |
52 |
Correct |
138 ms |
2796 KB |
Output is correct |
53 |
Correct |
157 ms |
2512 KB |
Output is correct |
54 |
Correct |
156 ms |
2688 KB |
Output is correct |
55 |
Correct |
181 ms |
3256 KB |
Output is correct |
56 |
Correct |
155 ms |
2640 KB |
Output is correct |
57 |
Correct |
173 ms |
3408 KB |
Output is correct |
58 |
Correct |
161 ms |
2764 KB |
Output is correct |
59 |
Correct |
168 ms |
2852 KB |
Output is correct |
60 |
Correct |
36 ms |
1872 KB |
Output is correct |
61 |
Correct |
158 ms |
3060 KB |
Output is correct |
62 |
Correct |
147 ms |
3128 KB |
Output is correct |
63 |
Correct |
175 ms |
3412 KB |
Output is correct |
64 |
Correct |
154 ms |
3260 KB |
Output is correct |
65 |
Correct |
144 ms |
2256 KB |
Output is correct |
66 |
Correct |
138 ms |
2288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1868 KB |
Output is correct |
2 |
Correct |
5 ms |
1868 KB |
Output is correct |
3 |
Correct |
3 ms |
1868 KB |
Output is correct |
4 |
Correct |
4 ms |
1868 KB |
Output is correct |
5 |
Correct |
8 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
1868 KB |
Output is correct |
7 |
Correct |
5 ms |
1868 KB |
Output is correct |
8 |
Correct |
7 ms |
1868 KB |
Output is correct |
9 |
Correct |
6 ms |
1868 KB |
Output is correct |
10 |
Correct |
15 ms |
1868 KB |
Output is correct |
11 |
Correct |
17 ms |
1884 KB |
Output is correct |
12 |
Correct |
15 ms |
1888 KB |
Output is correct |
13 |
Correct |
13 ms |
1884 KB |
Output is correct |
14 |
Correct |
14 ms |
1868 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
23 ms |
1884 KB |
Output is correct |
17 |
Correct |
12 ms |
1884 KB |
Output is correct |
18 |
Correct |
16 ms |
1868 KB |
Output is correct |
19 |
Correct |
16 ms |
1888 KB |
Output is correct |
20 |
Correct |
15 ms |
1896 KB |
Output is correct |
21 |
Correct |
29 ms |
1892 KB |
Output is correct |
22 |
Correct |
34 ms |
1924 KB |
Output is correct |
23 |
Correct |
32 ms |
1868 KB |
Output is correct |
24 |
Correct |
47 ms |
1908 KB |
Output is correct |
25 |
Correct |
52 ms |
1976 KB |
Output is correct |
26 |
Correct |
48 ms |
1892 KB |
Output is correct |
27 |
Correct |
49 ms |
1996 KB |
Output is correct |
28 |
Correct |
49 ms |
1944 KB |
Output is correct |
29 |
Correct |
46 ms |
1948 KB |
Output is correct |
30 |
Correct |
47 ms |
1896 KB |
Output is correct |
31 |
Correct |
47 ms |
1868 KB |
Output is correct |
32 |
Correct |
53 ms |
1908 KB |
Output is correct |
33 |
Correct |
47 ms |
1892 KB |
Output is correct |
34 |
Correct |
49 ms |
1948 KB |
Output is correct |
35 |
Correct |
45 ms |
1868 KB |
Output is correct |
36 |
Correct |
47 ms |
1920 KB |
Output is correct |
37 |
Correct |
105 ms |
2148 KB |
Output is correct |
38 |
Correct |
93 ms |
2132 KB |
Output is correct |
39 |
Correct |
120 ms |
2352 KB |
Output is correct |
40 |
Correct |
124 ms |
2252 KB |
Output is correct |
41 |
Correct |
137 ms |
2372 KB |
Output is correct |
42 |
Correct |
114 ms |
2240 KB |
Output is correct |
43 |
Correct |
114 ms |
2684 KB |
Output is correct |
44 |
Correct |
113 ms |
2620 KB |
Output is correct |
45 |
Correct |
123 ms |
2648 KB |
Output is correct |
46 |
Correct |
121 ms |
2020 KB |
Output is correct |
47 |
Correct |
115 ms |
2248 KB |
Output is correct |
48 |
Correct |
117 ms |
2660 KB |
Output is correct |
49 |
Correct |
126 ms |
2396 KB |
Output is correct |
50 |
Correct |
113 ms |
2252 KB |
Output is correct |
51 |
Correct |
25 ms |
1868 KB |
Output is correct |
52 |
Correct |
138 ms |
2796 KB |
Output is correct |
53 |
Correct |
157 ms |
2512 KB |
Output is correct |
54 |
Correct |
156 ms |
2688 KB |
Output is correct |
55 |
Correct |
181 ms |
3256 KB |
Output is correct |
56 |
Correct |
155 ms |
2640 KB |
Output is correct |
57 |
Correct |
173 ms |
3408 KB |
Output is correct |
58 |
Correct |
161 ms |
2764 KB |
Output is correct |
59 |
Correct |
168 ms |
2852 KB |
Output is correct |
60 |
Correct |
36 ms |
1872 KB |
Output is correct |
61 |
Correct |
158 ms |
3060 KB |
Output is correct |
62 |
Correct |
147 ms |
3128 KB |
Output is correct |
63 |
Correct |
175 ms |
3412 KB |
Output is correct |
64 |
Correct |
154 ms |
3260 KB |
Output is correct |
65 |
Correct |
144 ms |
2256 KB |
Output is correct |
66 |
Correct |
138 ms |
2288 KB |
Output is correct |
67 |
Correct |
235 ms |
2992 KB |
Output is correct |
68 |
Correct |
57 ms |
1876 KB |
Output is correct |
69 |
Incorrect |
271 ms |
4516 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |