// Make the best become better
// No room for laziness
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 500 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN];
int f[maxN * maxN];
int cnt[maxN * maxN];
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
cin >> a[i];
}
void Solve()
{
int sum = 0;
bool ok1 = false, ok2 = false;
for(int i=1; i<=n; i++)
{
sum += a[i];
if(a[i] & 1) ok1 = true;
else ok2 = true;
}
if(ok1 & ok2)
{
cout << 0;
return;
}
int tmp = sum;
f[0] = 1;
for(int i=1; i<=n; i++)
for(int s=tmp; s>=a[i]; s--)
f[s] += f[s - a[i]];
if(!f[sum / 2])
{
cout << 0;
return;
}
for(int i=1; i<=n; i++)
{
int cur = sum - a[i];
for(int s=a[i]; s<=tmp; s++)
f[s] -= f[s - a[i]];
for(int s=0; s<=tmp; s++)
if(f[s] && s * 2 > cur) cnt[s * 2 - cur]++;
for(int s=tmp; s>=a[i]; s--)
f[s] += f[s - a[i]];
}
vector<int> res;
for(int s=1; s<=tmp; s++)
if(cnt[s] == n) res.pb(s);
cout << res.size() << '\n';
for(int v : res)
cout << v << " ";
}
int32_t main()
{
// freopen("sol.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
4 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
4 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
464 KB |
Output is correct |
37 |
Correct |
12 ms |
908 KB |
Output is correct |
38 |
Correct |
12 ms |
916 KB |
Output is correct |
39 |
Correct |
37 ms |
1228 KB |
Output is correct |
40 |
Correct |
44 ms |
1092 KB |
Output is correct |
41 |
Correct |
49 ms |
1364 KB |
Output is correct |
42 |
Correct |
22 ms |
1108 KB |
Output is correct |
43 |
Correct |
44 ms |
1584 KB |
Output is correct |
44 |
Correct |
39 ms |
1600 KB |
Output is correct |
45 |
Correct |
45 ms |
1612 KB |
Output is correct |
46 |
Correct |
26 ms |
836 KB |
Output is correct |
47 |
Correct |
33 ms |
1088 KB |
Output is correct |
48 |
Correct |
53 ms |
1672 KB |
Output is correct |
49 |
Correct |
47 ms |
1412 KB |
Output is correct |
50 |
Correct |
23 ms |
1100 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
58 ms |
1936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
4 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
464 KB |
Output is correct |
37 |
Correct |
12 ms |
908 KB |
Output is correct |
38 |
Correct |
12 ms |
916 KB |
Output is correct |
39 |
Correct |
37 ms |
1228 KB |
Output is correct |
40 |
Correct |
44 ms |
1092 KB |
Output is correct |
41 |
Correct |
49 ms |
1364 KB |
Output is correct |
42 |
Correct |
22 ms |
1108 KB |
Output is correct |
43 |
Correct |
44 ms |
1584 KB |
Output is correct |
44 |
Correct |
39 ms |
1600 KB |
Output is correct |
45 |
Correct |
45 ms |
1612 KB |
Output is correct |
46 |
Correct |
26 ms |
836 KB |
Output is correct |
47 |
Correct |
33 ms |
1088 KB |
Output is correct |
48 |
Correct |
53 ms |
1672 KB |
Output is correct |
49 |
Correct |
47 ms |
1412 KB |
Output is correct |
50 |
Correct |
23 ms |
1100 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
58 ms |
1936 KB |
Output is correct |
53 |
Correct |
44 ms |
1428 KB |
Output is correct |
54 |
Correct |
54 ms |
1704 KB |
Output is correct |
55 |
Correct |
120 ms |
2892 KB |
Output is correct |
56 |
Correct |
48 ms |
1712 KB |
Output is correct |
57 |
Correct |
123 ms |
2916 KB |
Output is correct |
58 |
Correct |
60 ms |
1816 KB |
Output is correct |
59 |
Correct |
73 ms |
2164 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
95 ms |
2312 KB |
Output is correct |
62 |
Correct |
86 ms |
2604 KB |
Output is correct |
63 |
Correct |
102 ms |
2736 KB |
Output is correct |
64 |
Correct |
89 ms |
2636 KB |
Output is correct |
65 |
Correct |
43 ms |
1092 KB |
Output is correct |
66 |
Correct |
48 ms |
1284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
4 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
468 KB |
Output is correct |
28 |
Correct |
4 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
2 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
3 ms |
468 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
2 ms |
464 KB |
Output is correct |
37 |
Correct |
12 ms |
908 KB |
Output is correct |
38 |
Correct |
12 ms |
916 KB |
Output is correct |
39 |
Correct |
37 ms |
1228 KB |
Output is correct |
40 |
Correct |
44 ms |
1092 KB |
Output is correct |
41 |
Correct |
49 ms |
1364 KB |
Output is correct |
42 |
Correct |
22 ms |
1108 KB |
Output is correct |
43 |
Correct |
44 ms |
1584 KB |
Output is correct |
44 |
Correct |
39 ms |
1600 KB |
Output is correct |
45 |
Correct |
45 ms |
1612 KB |
Output is correct |
46 |
Correct |
26 ms |
836 KB |
Output is correct |
47 |
Correct |
33 ms |
1088 KB |
Output is correct |
48 |
Correct |
53 ms |
1672 KB |
Output is correct |
49 |
Correct |
47 ms |
1412 KB |
Output is correct |
50 |
Correct |
23 ms |
1100 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
58 ms |
1936 KB |
Output is correct |
53 |
Correct |
44 ms |
1428 KB |
Output is correct |
54 |
Correct |
54 ms |
1704 KB |
Output is correct |
55 |
Correct |
120 ms |
2892 KB |
Output is correct |
56 |
Correct |
48 ms |
1712 KB |
Output is correct |
57 |
Correct |
123 ms |
2916 KB |
Output is correct |
58 |
Correct |
60 ms |
1816 KB |
Output is correct |
59 |
Correct |
73 ms |
2164 KB |
Output is correct |
60 |
Correct |
1 ms |
336 KB |
Output is correct |
61 |
Correct |
95 ms |
2312 KB |
Output is correct |
62 |
Correct |
86 ms |
2604 KB |
Output is correct |
63 |
Correct |
102 ms |
2736 KB |
Output is correct |
64 |
Correct |
89 ms |
2636 KB |
Output is correct |
65 |
Correct |
43 ms |
1092 KB |
Output is correct |
66 |
Correct |
48 ms |
1284 KB |
Output is correct |
67 |
Correct |
115 ms |
2220 KB |
Output is correct |
68 |
Correct |
37 ms |
1304 KB |
Output is correct |
69 |
Correct |
280 ms |
5176 KB |
Output is correct |
70 |
Correct |
182 ms |
3348 KB |
Output is correct |
71 |
Correct |
169 ms |
3232 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
340 KB |
Output is correct |
74 |
Correct |
354 ms |
5488 KB |
Output is correct |
75 |
Correct |
257 ms |
4320 KB |
Output is correct |
76 |
Correct |
321 ms |
5692 KB |
Output is correct |
77 |
Correct |
309 ms |
5688 KB |
Output is correct |