#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 = 255000 + 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 |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
10 |
Correct |
19 ms |
2252 KB |
Output is correct |
11 |
Correct |
24 ms |
2324 KB |
Output is correct |
12 |
Correct |
22 ms |
2252 KB |
Output is correct |
13 |
Correct |
17 ms |
2324 KB |
Output is correct |
14 |
Correct |
19 ms |
2252 KB |
Output is correct |
15 |
Correct |
24 ms |
2252 KB |
Output is correct |
16 |
Correct |
21 ms |
2252 KB |
Output is correct |
17 |
Correct |
13 ms |
2316 KB |
Output is correct |
18 |
Correct |
15 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2316 KB |
Output is correct |
20 |
Correct |
20 ms |
2320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
10 |
Correct |
19 ms |
2252 KB |
Output is correct |
11 |
Correct |
24 ms |
2324 KB |
Output is correct |
12 |
Correct |
22 ms |
2252 KB |
Output is correct |
13 |
Correct |
17 ms |
2324 KB |
Output is correct |
14 |
Correct |
19 ms |
2252 KB |
Output is correct |
15 |
Correct |
24 ms |
2252 KB |
Output is correct |
16 |
Correct |
21 ms |
2252 KB |
Output is correct |
17 |
Correct |
13 ms |
2316 KB |
Output is correct |
18 |
Correct |
15 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2316 KB |
Output is correct |
20 |
Correct |
20 ms |
2320 KB |
Output is correct |
21 |
Correct |
38 ms |
2324 KB |
Output is correct |
22 |
Correct |
45 ms |
2336 KB |
Output is correct |
23 |
Correct |
33 ms |
2316 KB |
Output is correct |
24 |
Correct |
54 ms |
2316 KB |
Output is correct |
25 |
Correct |
55 ms |
2360 KB |
Output is correct |
26 |
Correct |
57 ms |
2380 KB |
Output is correct |
27 |
Correct |
56 ms |
2380 KB |
Output is correct |
28 |
Correct |
58 ms |
2444 KB |
Output is correct |
29 |
Correct |
57 ms |
2356 KB |
Output is correct |
30 |
Correct |
57 ms |
2252 KB |
Output is correct |
31 |
Correct |
59 ms |
2348 KB |
Output is correct |
32 |
Correct |
58 ms |
2332 KB |
Output is correct |
33 |
Correct |
57 ms |
2380 KB |
Output is correct |
34 |
Correct |
61 ms |
2500 KB |
Output is correct |
35 |
Correct |
59 ms |
2316 KB |
Output is correct |
36 |
Correct |
59 ms |
2340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
10 |
Correct |
19 ms |
2252 KB |
Output is correct |
11 |
Correct |
24 ms |
2324 KB |
Output is correct |
12 |
Correct |
22 ms |
2252 KB |
Output is correct |
13 |
Correct |
17 ms |
2324 KB |
Output is correct |
14 |
Correct |
19 ms |
2252 KB |
Output is correct |
15 |
Correct |
24 ms |
2252 KB |
Output is correct |
16 |
Correct |
21 ms |
2252 KB |
Output is correct |
17 |
Correct |
13 ms |
2316 KB |
Output is correct |
18 |
Correct |
15 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2316 KB |
Output is correct |
20 |
Correct |
20 ms |
2320 KB |
Output is correct |
21 |
Correct |
38 ms |
2324 KB |
Output is correct |
22 |
Correct |
45 ms |
2336 KB |
Output is correct |
23 |
Correct |
33 ms |
2316 KB |
Output is correct |
24 |
Correct |
54 ms |
2316 KB |
Output is correct |
25 |
Correct |
55 ms |
2360 KB |
Output is correct |
26 |
Correct |
57 ms |
2380 KB |
Output is correct |
27 |
Correct |
56 ms |
2380 KB |
Output is correct |
28 |
Correct |
58 ms |
2444 KB |
Output is correct |
29 |
Correct |
57 ms |
2356 KB |
Output is correct |
30 |
Correct |
57 ms |
2252 KB |
Output is correct |
31 |
Correct |
59 ms |
2348 KB |
Output is correct |
32 |
Correct |
58 ms |
2332 KB |
Output is correct |
33 |
Correct |
57 ms |
2380 KB |
Output is correct |
34 |
Correct |
61 ms |
2500 KB |
Output is correct |
35 |
Correct |
59 ms |
2316 KB |
Output is correct |
36 |
Correct |
59 ms |
2340 KB |
Output is correct |
37 |
Correct |
115 ms |
2564 KB |
Output is correct |
38 |
Correct |
116 ms |
2564 KB |
Output is correct |
39 |
Correct |
143 ms |
2772 KB |
Output is correct |
40 |
Correct |
166 ms |
2756 KB |
Output is correct |
41 |
Correct |
155 ms |
2820 KB |
Output is correct |
42 |
Correct |
140 ms |
2692 KB |
Output is correct |
43 |
Correct |
137 ms |
3108 KB |
Output is correct |
44 |
Correct |
146 ms |
3204 KB |
Output is correct |
45 |
Correct |
140 ms |
3072 KB |
Output is correct |
46 |
Correct |
152 ms |
2536 KB |
Output is correct |
47 |
Correct |
143 ms |
2672 KB |
Output is correct |
48 |
Correct |
152 ms |
3028 KB |
Output is correct |
49 |
Correct |
143 ms |
2776 KB |
Output is correct |
50 |
Correct |
142 ms |
2688 KB |
Output is correct |
51 |
Correct |
32 ms |
2252 KB |
Output is correct |
52 |
Correct |
158 ms |
3224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
10 |
Correct |
19 ms |
2252 KB |
Output is correct |
11 |
Correct |
24 ms |
2324 KB |
Output is correct |
12 |
Correct |
22 ms |
2252 KB |
Output is correct |
13 |
Correct |
17 ms |
2324 KB |
Output is correct |
14 |
Correct |
19 ms |
2252 KB |
Output is correct |
15 |
Correct |
24 ms |
2252 KB |
Output is correct |
16 |
Correct |
21 ms |
2252 KB |
Output is correct |
17 |
Correct |
13 ms |
2316 KB |
Output is correct |
18 |
Correct |
15 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2316 KB |
Output is correct |
20 |
Correct |
20 ms |
2320 KB |
Output is correct |
21 |
Correct |
38 ms |
2324 KB |
Output is correct |
22 |
Correct |
45 ms |
2336 KB |
Output is correct |
23 |
Correct |
33 ms |
2316 KB |
Output is correct |
24 |
Correct |
54 ms |
2316 KB |
Output is correct |
25 |
Correct |
55 ms |
2360 KB |
Output is correct |
26 |
Correct |
57 ms |
2380 KB |
Output is correct |
27 |
Correct |
56 ms |
2380 KB |
Output is correct |
28 |
Correct |
58 ms |
2444 KB |
Output is correct |
29 |
Correct |
57 ms |
2356 KB |
Output is correct |
30 |
Correct |
57 ms |
2252 KB |
Output is correct |
31 |
Correct |
59 ms |
2348 KB |
Output is correct |
32 |
Correct |
58 ms |
2332 KB |
Output is correct |
33 |
Correct |
57 ms |
2380 KB |
Output is correct |
34 |
Correct |
61 ms |
2500 KB |
Output is correct |
35 |
Correct |
59 ms |
2316 KB |
Output is correct |
36 |
Correct |
59 ms |
2340 KB |
Output is correct |
37 |
Correct |
115 ms |
2564 KB |
Output is correct |
38 |
Correct |
116 ms |
2564 KB |
Output is correct |
39 |
Correct |
143 ms |
2772 KB |
Output is correct |
40 |
Correct |
166 ms |
2756 KB |
Output is correct |
41 |
Correct |
155 ms |
2820 KB |
Output is correct |
42 |
Correct |
140 ms |
2692 KB |
Output is correct |
43 |
Correct |
137 ms |
3108 KB |
Output is correct |
44 |
Correct |
146 ms |
3204 KB |
Output is correct |
45 |
Correct |
140 ms |
3072 KB |
Output is correct |
46 |
Correct |
152 ms |
2536 KB |
Output is correct |
47 |
Correct |
143 ms |
2672 KB |
Output is correct |
48 |
Correct |
152 ms |
3028 KB |
Output is correct |
49 |
Correct |
143 ms |
2776 KB |
Output is correct |
50 |
Correct |
142 ms |
2688 KB |
Output is correct |
51 |
Correct |
32 ms |
2252 KB |
Output is correct |
52 |
Correct |
158 ms |
3224 KB |
Output is correct |
53 |
Correct |
179 ms |
2948 KB |
Output is correct |
54 |
Correct |
199 ms |
3076 KB |
Output is correct |
55 |
Correct |
206 ms |
3676 KB |
Output is correct |
56 |
Correct |
178 ms |
3116 KB |
Output is correct |
57 |
Correct |
207 ms |
3844 KB |
Output is correct |
58 |
Correct |
205 ms |
3156 KB |
Output is correct |
59 |
Correct |
210 ms |
3400 KB |
Output is correct |
60 |
Correct |
45 ms |
2252 KB |
Output is correct |
61 |
Correct |
198 ms |
3448 KB |
Output is correct |
62 |
Correct |
186 ms |
3656 KB |
Output is correct |
63 |
Correct |
190 ms |
3716 KB |
Output is correct |
64 |
Correct |
182 ms |
3656 KB |
Output is correct |
65 |
Correct |
203 ms |
2680 KB |
Output is correct |
66 |
Correct |
180 ms |
2824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
2252 KB |
Output is correct |
2 |
Correct |
6 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
4 ms |
2252 KB |
Output is correct |
5 |
Correct |
9 ms |
2252 KB |
Output is correct |
6 |
Correct |
7 ms |
2240 KB |
Output is correct |
7 |
Correct |
6 ms |
2252 KB |
Output is correct |
8 |
Correct |
11 ms |
2332 KB |
Output is correct |
9 |
Correct |
8 ms |
2320 KB |
Output is correct |
10 |
Correct |
19 ms |
2252 KB |
Output is correct |
11 |
Correct |
24 ms |
2324 KB |
Output is correct |
12 |
Correct |
22 ms |
2252 KB |
Output is correct |
13 |
Correct |
17 ms |
2324 KB |
Output is correct |
14 |
Correct |
19 ms |
2252 KB |
Output is correct |
15 |
Correct |
24 ms |
2252 KB |
Output is correct |
16 |
Correct |
21 ms |
2252 KB |
Output is correct |
17 |
Correct |
13 ms |
2316 KB |
Output is correct |
18 |
Correct |
15 ms |
2252 KB |
Output is correct |
19 |
Correct |
18 ms |
2316 KB |
Output is correct |
20 |
Correct |
20 ms |
2320 KB |
Output is correct |
21 |
Correct |
38 ms |
2324 KB |
Output is correct |
22 |
Correct |
45 ms |
2336 KB |
Output is correct |
23 |
Correct |
33 ms |
2316 KB |
Output is correct |
24 |
Correct |
54 ms |
2316 KB |
Output is correct |
25 |
Correct |
55 ms |
2360 KB |
Output is correct |
26 |
Correct |
57 ms |
2380 KB |
Output is correct |
27 |
Correct |
56 ms |
2380 KB |
Output is correct |
28 |
Correct |
58 ms |
2444 KB |
Output is correct |
29 |
Correct |
57 ms |
2356 KB |
Output is correct |
30 |
Correct |
57 ms |
2252 KB |
Output is correct |
31 |
Correct |
59 ms |
2348 KB |
Output is correct |
32 |
Correct |
58 ms |
2332 KB |
Output is correct |
33 |
Correct |
57 ms |
2380 KB |
Output is correct |
34 |
Correct |
61 ms |
2500 KB |
Output is correct |
35 |
Correct |
59 ms |
2316 KB |
Output is correct |
36 |
Correct |
59 ms |
2340 KB |
Output is correct |
37 |
Correct |
115 ms |
2564 KB |
Output is correct |
38 |
Correct |
116 ms |
2564 KB |
Output is correct |
39 |
Correct |
143 ms |
2772 KB |
Output is correct |
40 |
Correct |
166 ms |
2756 KB |
Output is correct |
41 |
Correct |
155 ms |
2820 KB |
Output is correct |
42 |
Correct |
140 ms |
2692 KB |
Output is correct |
43 |
Correct |
137 ms |
3108 KB |
Output is correct |
44 |
Correct |
146 ms |
3204 KB |
Output is correct |
45 |
Correct |
140 ms |
3072 KB |
Output is correct |
46 |
Correct |
152 ms |
2536 KB |
Output is correct |
47 |
Correct |
143 ms |
2672 KB |
Output is correct |
48 |
Correct |
152 ms |
3028 KB |
Output is correct |
49 |
Correct |
143 ms |
2776 KB |
Output is correct |
50 |
Correct |
142 ms |
2688 KB |
Output is correct |
51 |
Correct |
32 ms |
2252 KB |
Output is correct |
52 |
Correct |
158 ms |
3224 KB |
Output is correct |
53 |
Correct |
179 ms |
2948 KB |
Output is correct |
54 |
Correct |
199 ms |
3076 KB |
Output is correct |
55 |
Correct |
206 ms |
3676 KB |
Output is correct |
56 |
Correct |
178 ms |
3116 KB |
Output is correct |
57 |
Correct |
207 ms |
3844 KB |
Output is correct |
58 |
Correct |
205 ms |
3156 KB |
Output is correct |
59 |
Correct |
210 ms |
3400 KB |
Output is correct |
60 |
Correct |
45 ms |
2252 KB |
Output is correct |
61 |
Correct |
198 ms |
3448 KB |
Output is correct |
62 |
Correct |
186 ms |
3656 KB |
Output is correct |
63 |
Correct |
190 ms |
3716 KB |
Output is correct |
64 |
Correct |
182 ms |
3656 KB |
Output is correct |
65 |
Correct |
203 ms |
2680 KB |
Output is correct |
66 |
Correct |
180 ms |
2824 KB |
Output is correct |
67 |
Correct |
231 ms |
3452 KB |
Output is correct |
68 |
Correct |
64 ms |
2252 KB |
Output is correct |
69 |
Correct |
308 ms |
5092 KB |
Output is correct |
70 |
Correct |
301 ms |
4040 KB |
Output is correct |
71 |
Correct |
292 ms |
3968 KB |
Output is correct |
72 |
Correct |
295 ms |
3196 KB |
Output is correct |
73 |
Correct |
287 ms |
3200 KB |
Output is correct |
74 |
Correct |
314 ms |
5316 KB |
Output is correct |
75 |
Correct |
296 ms |
4604 KB |
Output is correct |
76 |
Correct |
307 ms |
5372 KB |
Output is correct |
77 |
Correct |
297 ms |
5368 KB |
Output is correct |