#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const ll MAX_N = 505;
const ll MAX_N2 = 255025;
ll sum,n,dp[MAX_N2],cnt[MAX_N2],a[MAX_N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(ll i=0; i<n; i++)
{
cin>>a[i];
sum+=a[i];
}
dp[0] = 1;
for(ll i=0; i<n; i++)
{
for(ll s=MAX_N2-a[i]-1; ; s--)
{
dp[s+a[i]] += dp[s];
if(s == 0) break;
}
}
if(sum%2 != 0 || dp[sum/2] == 0)
{
cout<<0<<endl;
return 0;
}
for(ll i=0; i<n; i++) /// ignore i-th
{
for(ll s=0; s+a[i]<MAX_N2; s++)
{
dp[s+a[i]] -= dp[s];
}
sum-=a[i];
for(ll x0=1; x0<=sum; x0++)
{
if((sum+x0)%2 == 0)
{
if(dp[(sum+x0)/2] > 0)
{
cnt[x0]++;
}
}
}
sum+=a[i];
for(ll s=MAX_N2-a[i]-1; ;s--)
{
dp[s+a[i]] += dp[s];
if(s == 0) break;
}
}
vector<ll> res;
for(ll x0=1; x0<MAX_N2; x0++)
{
if(cnt[x0] == n)
{
res.push_back(x0);
}
}
cout<<res.size()<<endl;
for(auto x: res) cout<<x<<" ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
10 |
Correct |
13 ms |
2312 KB |
Output is correct |
11 |
Correct |
15 ms |
2320 KB |
Output is correct |
12 |
Correct |
14 ms |
2252 KB |
Output is correct |
13 |
Correct |
13 ms |
2312 KB |
Output is correct |
14 |
Correct |
14 ms |
2312 KB |
Output is correct |
15 |
Correct |
14 ms |
2308 KB |
Output is correct |
16 |
Correct |
17 ms |
2316 KB |
Output is correct |
17 |
Correct |
10 ms |
2252 KB |
Output is correct |
18 |
Correct |
13 ms |
2316 KB |
Output is correct |
19 |
Correct |
15 ms |
2252 KB |
Output is correct |
20 |
Correct |
13 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
10 |
Correct |
13 ms |
2312 KB |
Output is correct |
11 |
Correct |
15 ms |
2320 KB |
Output is correct |
12 |
Correct |
14 ms |
2252 KB |
Output is correct |
13 |
Correct |
13 ms |
2312 KB |
Output is correct |
14 |
Correct |
14 ms |
2312 KB |
Output is correct |
15 |
Correct |
14 ms |
2308 KB |
Output is correct |
16 |
Correct |
17 ms |
2316 KB |
Output is correct |
17 |
Correct |
10 ms |
2252 KB |
Output is correct |
18 |
Correct |
13 ms |
2316 KB |
Output is correct |
19 |
Correct |
15 ms |
2252 KB |
Output is correct |
20 |
Correct |
13 ms |
2252 KB |
Output is correct |
21 |
Correct |
28 ms |
2324 KB |
Output is correct |
22 |
Correct |
31 ms |
2336 KB |
Output is correct |
23 |
Correct |
22 ms |
2252 KB |
Output is correct |
24 |
Correct |
39 ms |
2372 KB |
Output is correct |
25 |
Correct |
39 ms |
2368 KB |
Output is correct |
26 |
Correct |
42 ms |
2388 KB |
Output is correct |
27 |
Correct |
42 ms |
2380 KB |
Output is correct |
28 |
Correct |
40 ms |
2380 KB |
Output is correct |
29 |
Correct |
40 ms |
2376 KB |
Output is correct |
30 |
Correct |
40 ms |
2320 KB |
Output is correct |
31 |
Correct |
40 ms |
2372 KB |
Output is correct |
32 |
Correct |
41 ms |
2372 KB |
Output is correct |
33 |
Correct |
40 ms |
2380 KB |
Output is correct |
34 |
Correct |
41 ms |
2364 KB |
Output is correct |
35 |
Correct |
40 ms |
2380 KB |
Output is correct |
36 |
Correct |
41 ms |
2372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
10 |
Correct |
13 ms |
2312 KB |
Output is correct |
11 |
Correct |
15 ms |
2320 KB |
Output is correct |
12 |
Correct |
14 ms |
2252 KB |
Output is correct |
13 |
Correct |
13 ms |
2312 KB |
Output is correct |
14 |
Correct |
14 ms |
2312 KB |
Output is correct |
15 |
Correct |
14 ms |
2308 KB |
Output is correct |
16 |
Correct |
17 ms |
2316 KB |
Output is correct |
17 |
Correct |
10 ms |
2252 KB |
Output is correct |
18 |
Correct |
13 ms |
2316 KB |
Output is correct |
19 |
Correct |
15 ms |
2252 KB |
Output is correct |
20 |
Correct |
13 ms |
2252 KB |
Output is correct |
21 |
Correct |
28 ms |
2324 KB |
Output is correct |
22 |
Correct |
31 ms |
2336 KB |
Output is correct |
23 |
Correct |
22 ms |
2252 KB |
Output is correct |
24 |
Correct |
39 ms |
2372 KB |
Output is correct |
25 |
Correct |
39 ms |
2368 KB |
Output is correct |
26 |
Correct |
42 ms |
2388 KB |
Output is correct |
27 |
Correct |
42 ms |
2380 KB |
Output is correct |
28 |
Correct |
40 ms |
2380 KB |
Output is correct |
29 |
Correct |
40 ms |
2376 KB |
Output is correct |
30 |
Correct |
40 ms |
2320 KB |
Output is correct |
31 |
Correct |
40 ms |
2372 KB |
Output is correct |
32 |
Correct |
41 ms |
2372 KB |
Output is correct |
33 |
Correct |
40 ms |
2380 KB |
Output is correct |
34 |
Correct |
41 ms |
2364 KB |
Output is correct |
35 |
Correct |
40 ms |
2380 KB |
Output is correct |
36 |
Correct |
41 ms |
2372 KB |
Output is correct |
37 |
Correct |
82 ms |
2708 KB |
Output is correct |
38 |
Correct |
83 ms |
2692 KB |
Output is correct |
39 |
Correct |
109 ms |
2680 KB |
Output is correct |
40 |
Correct |
116 ms |
2824 KB |
Output is correct |
41 |
Correct |
125 ms |
2752 KB |
Output is correct |
42 |
Correct |
102 ms |
2808 KB |
Output is correct |
43 |
Correct |
107 ms |
3208 KB |
Output is correct |
44 |
Correct |
109 ms |
3128 KB |
Output is correct |
45 |
Correct |
116 ms |
3132 KB |
Output is correct |
46 |
Correct |
109 ms |
2540 KB |
Output is correct |
47 |
Correct |
104 ms |
2804 KB |
Output is correct |
48 |
Correct |
111 ms |
3160 KB |
Output is correct |
49 |
Correct |
109 ms |
2884 KB |
Output is correct |
50 |
Correct |
107 ms |
2808 KB |
Output is correct |
51 |
Correct |
32 ms |
2292 KB |
Output is correct |
52 |
Correct |
121 ms |
3324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
10 |
Correct |
13 ms |
2312 KB |
Output is correct |
11 |
Correct |
15 ms |
2320 KB |
Output is correct |
12 |
Correct |
14 ms |
2252 KB |
Output is correct |
13 |
Correct |
13 ms |
2312 KB |
Output is correct |
14 |
Correct |
14 ms |
2312 KB |
Output is correct |
15 |
Correct |
14 ms |
2308 KB |
Output is correct |
16 |
Correct |
17 ms |
2316 KB |
Output is correct |
17 |
Correct |
10 ms |
2252 KB |
Output is correct |
18 |
Correct |
13 ms |
2316 KB |
Output is correct |
19 |
Correct |
15 ms |
2252 KB |
Output is correct |
20 |
Correct |
13 ms |
2252 KB |
Output is correct |
21 |
Correct |
28 ms |
2324 KB |
Output is correct |
22 |
Correct |
31 ms |
2336 KB |
Output is correct |
23 |
Correct |
22 ms |
2252 KB |
Output is correct |
24 |
Correct |
39 ms |
2372 KB |
Output is correct |
25 |
Correct |
39 ms |
2368 KB |
Output is correct |
26 |
Correct |
42 ms |
2388 KB |
Output is correct |
27 |
Correct |
42 ms |
2380 KB |
Output is correct |
28 |
Correct |
40 ms |
2380 KB |
Output is correct |
29 |
Correct |
40 ms |
2376 KB |
Output is correct |
30 |
Correct |
40 ms |
2320 KB |
Output is correct |
31 |
Correct |
40 ms |
2372 KB |
Output is correct |
32 |
Correct |
41 ms |
2372 KB |
Output is correct |
33 |
Correct |
40 ms |
2380 KB |
Output is correct |
34 |
Correct |
41 ms |
2364 KB |
Output is correct |
35 |
Correct |
40 ms |
2380 KB |
Output is correct |
36 |
Correct |
41 ms |
2372 KB |
Output is correct |
37 |
Correct |
82 ms |
2708 KB |
Output is correct |
38 |
Correct |
83 ms |
2692 KB |
Output is correct |
39 |
Correct |
109 ms |
2680 KB |
Output is correct |
40 |
Correct |
116 ms |
2824 KB |
Output is correct |
41 |
Correct |
125 ms |
2752 KB |
Output is correct |
42 |
Correct |
102 ms |
2808 KB |
Output is correct |
43 |
Correct |
107 ms |
3208 KB |
Output is correct |
44 |
Correct |
109 ms |
3128 KB |
Output is correct |
45 |
Correct |
116 ms |
3132 KB |
Output is correct |
46 |
Correct |
109 ms |
2540 KB |
Output is correct |
47 |
Correct |
104 ms |
2804 KB |
Output is correct |
48 |
Correct |
111 ms |
3160 KB |
Output is correct |
49 |
Correct |
109 ms |
2884 KB |
Output is correct |
50 |
Correct |
107 ms |
2808 KB |
Output is correct |
51 |
Correct |
32 ms |
2292 KB |
Output is correct |
52 |
Correct |
121 ms |
3324 KB |
Output is correct |
53 |
Correct |
126 ms |
3004 KB |
Output is correct |
54 |
Correct |
151 ms |
3200 KB |
Output is correct |
55 |
Correct |
174 ms |
3936 KB |
Output is correct |
56 |
Correct |
136 ms |
3208 KB |
Output is correct |
57 |
Correct |
174 ms |
3976 KB |
Output is correct |
58 |
Correct |
158 ms |
3300 KB |
Output is correct |
59 |
Correct |
159 ms |
3528 KB |
Output is correct |
60 |
Correct |
45 ms |
2232 KB |
Output is correct |
61 |
Correct |
168 ms |
3608 KB |
Output is correct |
62 |
Correct |
166 ms |
3780 KB |
Output is correct |
63 |
Correct |
157 ms |
3840 KB |
Output is correct |
64 |
Correct |
155 ms |
3860 KB |
Output is correct |
65 |
Correct |
140 ms |
2692 KB |
Output is correct |
66 |
Correct |
136 ms |
2820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 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 |
7 ms |
2312 KB |
Output is correct |
6 |
Correct |
5 ms |
2252 KB |
Output is correct |
7 |
Correct |
5 ms |
2252 KB |
Output is correct |
8 |
Correct |
7 ms |
2252 KB |
Output is correct |
9 |
Correct |
6 ms |
2320 KB |
Output is correct |
10 |
Correct |
13 ms |
2312 KB |
Output is correct |
11 |
Correct |
15 ms |
2320 KB |
Output is correct |
12 |
Correct |
14 ms |
2252 KB |
Output is correct |
13 |
Correct |
13 ms |
2312 KB |
Output is correct |
14 |
Correct |
14 ms |
2312 KB |
Output is correct |
15 |
Correct |
14 ms |
2308 KB |
Output is correct |
16 |
Correct |
17 ms |
2316 KB |
Output is correct |
17 |
Correct |
10 ms |
2252 KB |
Output is correct |
18 |
Correct |
13 ms |
2316 KB |
Output is correct |
19 |
Correct |
15 ms |
2252 KB |
Output is correct |
20 |
Correct |
13 ms |
2252 KB |
Output is correct |
21 |
Correct |
28 ms |
2324 KB |
Output is correct |
22 |
Correct |
31 ms |
2336 KB |
Output is correct |
23 |
Correct |
22 ms |
2252 KB |
Output is correct |
24 |
Correct |
39 ms |
2372 KB |
Output is correct |
25 |
Correct |
39 ms |
2368 KB |
Output is correct |
26 |
Correct |
42 ms |
2388 KB |
Output is correct |
27 |
Correct |
42 ms |
2380 KB |
Output is correct |
28 |
Correct |
40 ms |
2380 KB |
Output is correct |
29 |
Correct |
40 ms |
2376 KB |
Output is correct |
30 |
Correct |
40 ms |
2320 KB |
Output is correct |
31 |
Correct |
40 ms |
2372 KB |
Output is correct |
32 |
Correct |
41 ms |
2372 KB |
Output is correct |
33 |
Correct |
40 ms |
2380 KB |
Output is correct |
34 |
Correct |
41 ms |
2364 KB |
Output is correct |
35 |
Correct |
40 ms |
2380 KB |
Output is correct |
36 |
Correct |
41 ms |
2372 KB |
Output is correct |
37 |
Correct |
82 ms |
2708 KB |
Output is correct |
38 |
Correct |
83 ms |
2692 KB |
Output is correct |
39 |
Correct |
109 ms |
2680 KB |
Output is correct |
40 |
Correct |
116 ms |
2824 KB |
Output is correct |
41 |
Correct |
125 ms |
2752 KB |
Output is correct |
42 |
Correct |
102 ms |
2808 KB |
Output is correct |
43 |
Correct |
107 ms |
3208 KB |
Output is correct |
44 |
Correct |
109 ms |
3128 KB |
Output is correct |
45 |
Correct |
116 ms |
3132 KB |
Output is correct |
46 |
Correct |
109 ms |
2540 KB |
Output is correct |
47 |
Correct |
104 ms |
2804 KB |
Output is correct |
48 |
Correct |
111 ms |
3160 KB |
Output is correct |
49 |
Correct |
109 ms |
2884 KB |
Output is correct |
50 |
Correct |
107 ms |
2808 KB |
Output is correct |
51 |
Correct |
32 ms |
2292 KB |
Output is correct |
52 |
Correct |
121 ms |
3324 KB |
Output is correct |
53 |
Correct |
126 ms |
3004 KB |
Output is correct |
54 |
Correct |
151 ms |
3200 KB |
Output is correct |
55 |
Correct |
174 ms |
3936 KB |
Output is correct |
56 |
Correct |
136 ms |
3208 KB |
Output is correct |
57 |
Correct |
174 ms |
3976 KB |
Output is correct |
58 |
Correct |
158 ms |
3300 KB |
Output is correct |
59 |
Correct |
159 ms |
3528 KB |
Output is correct |
60 |
Correct |
45 ms |
2232 KB |
Output is correct |
61 |
Correct |
168 ms |
3608 KB |
Output is correct |
62 |
Correct |
166 ms |
3780 KB |
Output is correct |
63 |
Correct |
157 ms |
3840 KB |
Output is correct |
64 |
Correct |
155 ms |
3860 KB |
Output is correct |
65 |
Correct |
140 ms |
2692 KB |
Output is correct |
66 |
Correct |
136 ms |
2820 KB |
Output is correct |
67 |
Correct |
183 ms |
3500 KB |
Output is correct |
68 |
Correct |
63 ms |
2252 KB |
Output is correct |
69 |
Correct |
306 ms |
5504 KB |
Output is correct |
70 |
Correct |
252 ms |
4216 KB |
Output is correct |
71 |
Correct |
254 ms |
4164 KB |
Output is correct |
72 |
Correct |
239 ms |
3276 KB |
Output is correct |
73 |
Correct |
238 ms |
3272 KB |
Output is correct |
74 |
Correct |
307 ms |
5824 KB |
Output is correct |
75 |
Correct |
277 ms |
4928 KB |
Output is correct |
76 |
Correct |
322 ms |
5764 KB |
Output is correct |
77 |
Correct |
313 ms |
5892 KB |
Output is correct |