#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double
const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n;
cin>>n;
int a[n+2];
int sum = 0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum += a[i];
}
int dp[sum+2];
clr(dp, 0);
dp[0] = 1;
for(int i=1;i<=n;i++){
for(int j=sum;j>=a[i];j--){
if(j >= a[i]) dp[j] += dp[j-a[i]];
}
}
if(dp[sum/2] == 0){
cout<<0<<endl;
return 0;
}
int cnt[sum+2];
clr(cnt, 0);
for(int i=1;i<=n;i++){
for(int j=a[i];j<=sum;j++){
dp[j] -= dp[j-a[i]];
}
int mx = sum-a[i];
for(int j=0;j<=sum;j++){
int x = 2*j-mx;
if(dp[j] != 0 && x >= 0){
cnt[x]++;
}
}
for(int j=sum;j>=a[i];j--){
dp[j] += dp[j-a[i]];
}
}
vector<int> ans;
for(int i=1;i<=sum;i++){
if(cnt[i] == n) ans.pb(i);
}
cout<<ans.size()<<endl;
printvector(ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
440 KB |
Output is correct |
26 |
Correct |
4 ms |
440 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
440 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
444 KB |
Output is correct |
35 |
Correct |
5 ms |
464 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
440 KB |
Output is correct |
26 |
Correct |
4 ms |
440 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
440 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
444 KB |
Output is correct |
35 |
Correct |
5 ms |
464 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
17 ms |
872 KB |
Output is correct |
38 |
Correct |
13 ms |
844 KB |
Output is correct |
39 |
Correct |
48 ms |
1172 KB |
Output is correct |
40 |
Correct |
27 ms |
1052 KB |
Output is correct |
41 |
Correct |
64 ms |
1396 KB |
Output is correct |
42 |
Correct |
23 ms |
1084 KB |
Output is correct |
43 |
Correct |
41 ms |
1632 KB |
Output is correct |
44 |
Correct |
46 ms |
1564 KB |
Output is correct |
45 |
Correct |
47 ms |
1700 KB |
Output is correct |
46 |
Correct |
32 ms |
696 KB |
Output is correct |
47 |
Correct |
25 ms |
1072 KB |
Output is correct |
48 |
Correct |
49 ms |
1652 KB |
Output is correct |
49 |
Correct |
48 ms |
1268 KB |
Output is correct |
50 |
Correct |
26 ms |
1072 KB |
Output is correct |
51 |
Correct |
24 ms |
692 KB |
Output is correct |
52 |
Correct |
65 ms |
1908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
440 KB |
Output is correct |
26 |
Correct |
4 ms |
440 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
440 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
444 KB |
Output is correct |
35 |
Correct |
5 ms |
464 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
17 ms |
872 KB |
Output is correct |
38 |
Correct |
13 ms |
844 KB |
Output is correct |
39 |
Correct |
48 ms |
1172 KB |
Output is correct |
40 |
Correct |
27 ms |
1052 KB |
Output is correct |
41 |
Correct |
64 ms |
1396 KB |
Output is correct |
42 |
Correct |
23 ms |
1084 KB |
Output is correct |
43 |
Correct |
41 ms |
1632 KB |
Output is correct |
44 |
Correct |
46 ms |
1564 KB |
Output is correct |
45 |
Correct |
47 ms |
1700 KB |
Output is correct |
46 |
Correct |
32 ms |
696 KB |
Output is correct |
47 |
Correct |
25 ms |
1072 KB |
Output is correct |
48 |
Correct |
49 ms |
1652 KB |
Output is correct |
49 |
Correct |
48 ms |
1268 KB |
Output is correct |
50 |
Correct |
26 ms |
1072 KB |
Output is correct |
51 |
Correct |
24 ms |
692 KB |
Output is correct |
52 |
Correct |
65 ms |
1908 KB |
Output is correct |
53 |
Correct |
43 ms |
1404 KB |
Output is correct |
54 |
Correct |
61 ms |
1680 KB |
Output is correct |
55 |
Correct |
125 ms |
2792 KB |
Output is correct |
56 |
Correct |
52 ms |
1664 KB |
Output is correct |
57 |
Correct |
132 ms |
2892 KB |
Output is correct |
58 |
Correct |
76 ms |
1772 KB |
Output is correct |
59 |
Correct |
81 ms |
2120 KB |
Output is correct |
60 |
Correct |
62 ms |
1228 KB |
Output is correct |
61 |
Correct |
104 ms |
2256 KB |
Output is correct |
62 |
Correct |
106 ms |
2628 KB |
Output is correct |
63 |
Correct |
105 ms |
2684 KB |
Output is correct |
64 |
Correct |
97 ms |
2640 KB |
Output is correct |
65 |
Correct |
50 ms |
1040 KB |
Output is correct |
66 |
Correct |
50 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
312 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
3 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
3 ms |
332 KB |
Output is correct |
25 |
Correct |
4 ms |
440 KB |
Output is correct |
26 |
Correct |
4 ms |
440 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
4 ms |
460 KB |
Output is correct |
32 |
Correct |
3 ms |
440 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
444 KB |
Output is correct |
35 |
Correct |
5 ms |
464 KB |
Output is correct |
36 |
Correct |
2 ms |
332 KB |
Output is correct |
37 |
Correct |
17 ms |
872 KB |
Output is correct |
38 |
Correct |
13 ms |
844 KB |
Output is correct |
39 |
Correct |
48 ms |
1172 KB |
Output is correct |
40 |
Correct |
27 ms |
1052 KB |
Output is correct |
41 |
Correct |
64 ms |
1396 KB |
Output is correct |
42 |
Correct |
23 ms |
1084 KB |
Output is correct |
43 |
Correct |
41 ms |
1632 KB |
Output is correct |
44 |
Correct |
46 ms |
1564 KB |
Output is correct |
45 |
Correct |
47 ms |
1700 KB |
Output is correct |
46 |
Correct |
32 ms |
696 KB |
Output is correct |
47 |
Correct |
25 ms |
1072 KB |
Output is correct |
48 |
Correct |
49 ms |
1652 KB |
Output is correct |
49 |
Correct |
48 ms |
1268 KB |
Output is correct |
50 |
Correct |
26 ms |
1072 KB |
Output is correct |
51 |
Correct |
24 ms |
692 KB |
Output is correct |
52 |
Correct |
65 ms |
1908 KB |
Output is correct |
53 |
Correct |
43 ms |
1404 KB |
Output is correct |
54 |
Correct |
61 ms |
1680 KB |
Output is correct |
55 |
Correct |
125 ms |
2792 KB |
Output is correct |
56 |
Correct |
52 ms |
1664 KB |
Output is correct |
57 |
Correct |
132 ms |
2892 KB |
Output is correct |
58 |
Correct |
76 ms |
1772 KB |
Output is correct |
59 |
Correct |
81 ms |
2120 KB |
Output is correct |
60 |
Correct |
62 ms |
1228 KB |
Output is correct |
61 |
Correct |
104 ms |
2256 KB |
Output is correct |
62 |
Correct |
106 ms |
2628 KB |
Output is correct |
63 |
Correct |
105 ms |
2684 KB |
Output is correct |
64 |
Correct |
97 ms |
2640 KB |
Output is correct |
65 |
Correct |
50 ms |
1040 KB |
Output is correct |
66 |
Correct |
50 ms |
1236 KB |
Output is correct |
67 |
Correct |
105 ms |
2232 KB |
Output is correct |
68 |
Correct |
43 ms |
1228 KB |
Output is correct |
69 |
Correct |
312 ms |
5164 KB |
Output is correct |
70 |
Correct |
193 ms |
3212 KB |
Output is correct |
71 |
Correct |
181 ms |
3136 KB |
Output is correct |
72 |
Correct |
180 ms |
2188 KB |
Output is correct |
73 |
Correct |
187 ms |
2248 KB |
Output is correct |
74 |
Correct |
352 ms |
5496 KB |
Output is correct |
75 |
Correct |
277 ms |
4356 KB |
Output is correct |
76 |
Correct |
360 ms |
5652 KB |
Output is correct |
77 |
Correct |
353 ms |
5728 KB |
Output is correct |