#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 5e2 + 1, maxm = 3e5 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
int n, sum;
int a[maxn], dp[maxm], cnt[maxm], ans[maxm];
int main(){
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; ++i){
cin >> a[i];
for(int j = maxm - 1; j >= a[i]; j--)
dp[j] += dp[j - a[i]];
sum += a[i];
}
if (sum % 2 != 0 || dp[sum / 2] == 0){
cout << 0;
return 0;
}
for (int i = 1; i <= n; ++i){
for (int j = a[i]; j <= maxm - 1; ++j){
dp[j] -= dp[j - a[i]];
}
for (int j = 0; j <= maxm - 1; ++j){
if (dp[j]){
int f = j, s = sum - a[i] - j;
int rz = abs(f - s);
cnt[rz] = 1;
}
}
for (int j = 0; j <= maxm - 1; ++j){
if (cnt[j] > 0){
ans[j]++;
}
cnt[j] = 0;
}
for (int j = maxm - 1; j >= a[i]; --j){
dp[j] += dp[j - a[i]];
}
}
vector<int> v;
for (int i = 1; i <= maxm - 1; ++i){
if (ans[i] == n){
v.pb(i);
}
}
cout << v.size() << '\n';
for (auto it : v){
cout << it << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
2628 KB |
Output is correct |
13 |
Correct |
29 ms |
2636 KB |
Output is correct |
14 |
Correct |
31 ms |
2652 KB |
Output is correct |
15 |
Correct |
33 ms |
2636 KB |
Output is correct |
16 |
Correct |
49 ms |
2636 KB |
Output is correct |
17 |
Correct |
34 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2636 KB |
Output is correct |
19 |
Correct |
30 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
2628 KB |
Output is correct |
13 |
Correct |
29 ms |
2636 KB |
Output is correct |
14 |
Correct |
31 ms |
2652 KB |
Output is correct |
15 |
Correct |
33 ms |
2636 KB |
Output is correct |
16 |
Correct |
49 ms |
2636 KB |
Output is correct |
17 |
Correct |
34 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2636 KB |
Output is correct |
19 |
Correct |
30 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2632 KB |
Output is correct |
21 |
Correct |
70 ms |
2636 KB |
Output is correct |
22 |
Correct |
82 ms |
2636 KB |
Output is correct |
23 |
Correct |
57 ms |
2652 KB |
Output is correct |
24 |
Correct |
125 ms |
2644 KB |
Output is correct |
25 |
Correct |
95 ms |
2656 KB |
Output is correct |
26 |
Correct |
101 ms |
2664 KB |
Output is correct |
27 |
Correct |
103 ms |
2664 KB |
Output is correct |
28 |
Correct |
134 ms |
2664 KB |
Output is correct |
29 |
Correct |
106 ms |
2660 KB |
Output is correct |
30 |
Correct |
104 ms |
2648 KB |
Output is correct |
31 |
Correct |
102 ms |
2656 KB |
Output is correct |
32 |
Correct |
106 ms |
2644 KB |
Output is correct |
33 |
Correct |
102 ms |
2636 KB |
Output is correct |
34 |
Correct |
135 ms |
2660 KB |
Output is correct |
35 |
Correct |
106 ms |
2664 KB |
Output is correct |
36 |
Correct |
102 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
2628 KB |
Output is correct |
13 |
Correct |
29 ms |
2636 KB |
Output is correct |
14 |
Correct |
31 ms |
2652 KB |
Output is correct |
15 |
Correct |
33 ms |
2636 KB |
Output is correct |
16 |
Correct |
49 ms |
2636 KB |
Output is correct |
17 |
Correct |
34 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2636 KB |
Output is correct |
19 |
Correct |
30 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2632 KB |
Output is correct |
21 |
Correct |
70 ms |
2636 KB |
Output is correct |
22 |
Correct |
82 ms |
2636 KB |
Output is correct |
23 |
Correct |
57 ms |
2652 KB |
Output is correct |
24 |
Correct |
125 ms |
2644 KB |
Output is correct |
25 |
Correct |
95 ms |
2656 KB |
Output is correct |
26 |
Correct |
101 ms |
2664 KB |
Output is correct |
27 |
Correct |
103 ms |
2664 KB |
Output is correct |
28 |
Correct |
134 ms |
2664 KB |
Output is correct |
29 |
Correct |
106 ms |
2660 KB |
Output is correct |
30 |
Correct |
104 ms |
2648 KB |
Output is correct |
31 |
Correct |
102 ms |
2656 KB |
Output is correct |
32 |
Correct |
106 ms |
2644 KB |
Output is correct |
33 |
Correct |
102 ms |
2636 KB |
Output is correct |
34 |
Correct |
135 ms |
2660 KB |
Output is correct |
35 |
Correct |
106 ms |
2664 KB |
Output is correct |
36 |
Correct |
102 ms |
2636 KB |
Output is correct |
37 |
Correct |
199 ms |
2732 KB |
Output is correct |
38 |
Correct |
211 ms |
2828 KB |
Output is correct |
39 |
Correct |
255 ms |
2756 KB |
Output is correct |
40 |
Correct |
318 ms |
2872 KB |
Output is correct |
41 |
Correct |
298 ms |
2912 KB |
Output is correct |
42 |
Correct |
250 ms |
2864 KB |
Output is correct |
43 |
Correct |
256 ms |
3140 KB |
Output is correct |
44 |
Correct |
304 ms |
3224 KB |
Output is correct |
45 |
Correct |
255 ms |
3236 KB |
Output is correct |
46 |
Correct |
358 ms |
2860 KB |
Output is correct |
47 |
Correct |
255 ms |
2888 KB |
Output is correct |
48 |
Correct |
273 ms |
3120 KB |
Output is correct |
49 |
Correct |
274 ms |
2864 KB |
Output is correct |
50 |
Correct |
255 ms |
2884 KB |
Output is correct |
51 |
Correct |
46 ms |
1476 KB |
Output is correct |
52 |
Correct |
296 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
2628 KB |
Output is correct |
13 |
Correct |
29 ms |
2636 KB |
Output is correct |
14 |
Correct |
31 ms |
2652 KB |
Output is correct |
15 |
Correct |
33 ms |
2636 KB |
Output is correct |
16 |
Correct |
49 ms |
2636 KB |
Output is correct |
17 |
Correct |
34 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2636 KB |
Output is correct |
19 |
Correct |
30 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2632 KB |
Output is correct |
21 |
Correct |
70 ms |
2636 KB |
Output is correct |
22 |
Correct |
82 ms |
2636 KB |
Output is correct |
23 |
Correct |
57 ms |
2652 KB |
Output is correct |
24 |
Correct |
125 ms |
2644 KB |
Output is correct |
25 |
Correct |
95 ms |
2656 KB |
Output is correct |
26 |
Correct |
101 ms |
2664 KB |
Output is correct |
27 |
Correct |
103 ms |
2664 KB |
Output is correct |
28 |
Correct |
134 ms |
2664 KB |
Output is correct |
29 |
Correct |
106 ms |
2660 KB |
Output is correct |
30 |
Correct |
104 ms |
2648 KB |
Output is correct |
31 |
Correct |
102 ms |
2656 KB |
Output is correct |
32 |
Correct |
106 ms |
2644 KB |
Output is correct |
33 |
Correct |
102 ms |
2636 KB |
Output is correct |
34 |
Correct |
135 ms |
2660 KB |
Output is correct |
35 |
Correct |
106 ms |
2664 KB |
Output is correct |
36 |
Correct |
102 ms |
2636 KB |
Output is correct |
37 |
Correct |
199 ms |
2732 KB |
Output is correct |
38 |
Correct |
211 ms |
2828 KB |
Output is correct |
39 |
Correct |
255 ms |
2756 KB |
Output is correct |
40 |
Correct |
318 ms |
2872 KB |
Output is correct |
41 |
Correct |
298 ms |
2912 KB |
Output is correct |
42 |
Correct |
250 ms |
2864 KB |
Output is correct |
43 |
Correct |
256 ms |
3140 KB |
Output is correct |
44 |
Correct |
304 ms |
3224 KB |
Output is correct |
45 |
Correct |
255 ms |
3236 KB |
Output is correct |
46 |
Correct |
358 ms |
2860 KB |
Output is correct |
47 |
Correct |
255 ms |
2888 KB |
Output is correct |
48 |
Correct |
273 ms |
3120 KB |
Output is correct |
49 |
Correct |
274 ms |
2864 KB |
Output is correct |
50 |
Correct |
255 ms |
2884 KB |
Output is correct |
51 |
Correct |
46 ms |
1476 KB |
Output is correct |
52 |
Correct |
296 ms |
3372 KB |
Output is correct |
53 |
Correct |
347 ms |
3140 KB |
Output is correct |
54 |
Correct |
433 ms |
3228 KB |
Output is correct |
55 |
Correct |
379 ms |
3648 KB |
Output is correct |
56 |
Correct |
342 ms |
3244 KB |
Output is correct |
57 |
Correct |
365 ms |
3720 KB |
Output is correct |
58 |
Correct |
377 ms |
3252 KB |
Output is correct |
59 |
Correct |
373 ms |
3312 KB |
Output is correct |
60 |
Correct |
56 ms |
1356 KB |
Output is correct |
61 |
Correct |
445 ms |
3520 KB |
Output is correct |
62 |
Correct |
355 ms |
3504 KB |
Output is correct |
63 |
Correct |
368 ms |
3648 KB |
Output is correct |
64 |
Correct |
335 ms |
3624 KB |
Output is correct |
65 |
Correct |
331 ms |
2868 KB |
Output is correct |
66 |
Correct |
333 ms |
2832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2636 KB |
Output is correct |
2 |
Correct |
9 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
1356 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
21 ms |
2644 KB |
Output is correct |
6 |
Correct |
13 ms |
2644 KB |
Output is correct |
7 |
Correct |
10 ms |
2648 KB |
Output is correct |
8 |
Correct |
15 ms |
2636 KB |
Output is correct |
9 |
Correct |
13 ms |
2644 KB |
Output is correct |
10 |
Correct |
32 ms |
2636 KB |
Output is correct |
11 |
Correct |
34 ms |
2620 KB |
Output is correct |
12 |
Correct |
32 ms |
2628 KB |
Output is correct |
13 |
Correct |
29 ms |
2636 KB |
Output is correct |
14 |
Correct |
31 ms |
2652 KB |
Output is correct |
15 |
Correct |
33 ms |
2636 KB |
Output is correct |
16 |
Correct |
49 ms |
2636 KB |
Output is correct |
17 |
Correct |
34 ms |
2636 KB |
Output is correct |
18 |
Correct |
28 ms |
2636 KB |
Output is correct |
19 |
Correct |
30 ms |
2636 KB |
Output is correct |
20 |
Correct |
32 ms |
2632 KB |
Output is correct |
21 |
Correct |
70 ms |
2636 KB |
Output is correct |
22 |
Correct |
82 ms |
2636 KB |
Output is correct |
23 |
Correct |
57 ms |
2652 KB |
Output is correct |
24 |
Correct |
125 ms |
2644 KB |
Output is correct |
25 |
Correct |
95 ms |
2656 KB |
Output is correct |
26 |
Correct |
101 ms |
2664 KB |
Output is correct |
27 |
Correct |
103 ms |
2664 KB |
Output is correct |
28 |
Correct |
134 ms |
2664 KB |
Output is correct |
29 |
Correct |
106 ms |
2660 KB |
Output is correct |
30 |
Correct |
104 ms |
2648 KB |
Output is correct |
31 |
Correct |
102 ms |
2656 KB |
Output is correct |
32 |
Correct |
106 ms |
2644 KB |
Output is correct |
33 |
Correct |
102 ms |
2636 KB |
Output is correct |
34 |
Correct |
135 ms |
2660 KB |
Output is correct |
35 |
Correct |
106 ms |
2664 KB |
Output is correct |
36 |
Correct |
102 ms |
2636 KB |
Output is correct |
37 |
Correct |
199 ms |
2732 KB |
Output is correct |
38 |
Correct |
211 ms |
2828 KB |
Output is correct |
39 |
Correct |
255 ms |
2756 KB |
Output is correct |
40 |
Correct |
318 ms |
2872 KB |
Output is correct |
41 |
Correct |
298 ms |
2912 KB |
Output is correct |
42 |
Correct |
250 ms |
2864 KB |
Output is correct |
43 |
Correct |
256 ms |
3140 KB |
Output is correct |
44 |
Correct |
304 ms |
3224 KB |
Output is correct |
45 |
Correct |
255 ms |
3236 KB |
Output is correct |
46 |
Correct |
358 ms |
2860 KB |
Output is correct |
47 |
Correct |
255 ms |
2888 KB |
Output is correct |
48 |
Correct |
273 ms |
3120 KB |
Output is correct |
49 |
Correct |
274 ms |
2864 KB |
Output is correct |
50 |
Correct |
255 ms |
2884 KB |
Output is correct |
51 |
Correct |
46 ms |
1476 KB |
Output is correct |
52 |
Correct |
296 ms |
3372 KB |
Output is correct |
53 |
Correct |
347 ms |
3140 KB |
Output is correct |
54 |
Correct |
433 ms |
3228 KB |
Output is correct |
55 |
Correct |
379 ms |
3648 KB |
Output is correct |
56 |
Correct |
342 ms |
3244 KB |
Output is correct |
57 |
Correct |
365 ms |
3720 KB |
Output is correct |
58 |
Correct |
377 ms |
3252 KB |
Output is correct |
59 |
Correct |
373 ms |
3312 KB |
Output is correct |
60 |
Correct |
56 ms |
1356 KB |
Output is correct |
61 |
Correct |
445 ms |
3520 KB |
Output is correct |
62 |
Correct |
355 ms |
3504 KB |
Output is correct |
63 |
Correct |
368 ms |
3648 KB |
Output is correct |
64 |
Correct |
335 ms |
3624 KB |
Output is correct |
65 |
Correct |
331 ms |
2868 KB |
Output is correct |
66 |
Correct |
333 ms |
2832 KB |
Output is correct |
67 |
Correct |
459 ms |
3444 KB |
Output is correct |
68 |
Correct |
74 ms |
1356 KB |
Output is correct |
69 |
Correct |
608 ms |
4592 KB |
Output is correct |
70 |
Correct |
534 ms |
3896 KB |
Output is correct |
71 |
Correct |
641 ms |
3876 KB |
Output is correct |
72 |
Correct |
560 ms |
3116 KB |
Output is correct |
73 |
Correct |
562 ms |
3116 KB |
Output is correct |
74 |
Correct |
587 ms |
4644 KB |
Output is correct |
75 |
Correct |
550 ms |
4328 KB |
Output is correct |
76 |
Correct |
583 ms |
4796 KB |
Output is correct |
77 |
Correct |
604 ms |
4828 KB |
Output is correct |