/* Murad Eynizade */
#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 100001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);
#define MOD 1000000007
using namespace std;
bool f = false;
int dp[250005],sum , mx , can[250005];
vector<int>ans;
int main()
{
FAST_READ;
int n;
cin>>n;
int a[n];
for (int i = 0;i<n;i++)cin>>a[i] , sum += a[i];
sort(a,a+n);
dp[0] = 1;
for (int i = 0;i<n;i++)
for (int j = sum;j >= a[i];j--)
dp[j] += dp[j - a[i]];
if (sum % 2) {
cout<<0<<endl;
return 0;
}
for (int i = 1;i<sum;i++) {
if (dp[i] && i == sum / 2) {
f = true;
break;
}
}
if (!f) {
cout<<0<<endl;
return 0;
}
for (int no = 1;no<=n;no++) {
f = false;
mx = -1;
int oldsum = sum;
sum -= a[no - 1];
if (no == 1 || a[no - 1] != a[no - 2]) {
for (int i = a[no - 1];i<=oldsum;i++)
dp[i] -= dp[i - a[no - 1]];
}
for (int i = 1;i<=sum;i++) {
if (dp[i] && can[abs(i - (sum - i))] == no - 1) {
can[abs(i - (sum - i))] = no;
if (no == n)ans.push_back(abs(i - (sum - i)));
f = true;
}
}
if (!f) {
cout<<0<<endl;
return 0;
}
sum = oldsum;
if (no == n || a[no - 1] != a[no]) {
for (int i = sum;i>=a[no - 1];i--)
dp[i] += dp[i - a[no - 1]];
}
}
int sz = ans.size();
if (sz == 0)cout<<0<<endl;
else {
cout<<sz<<endl;
sort(ans.begin(),ans.end());
for (int i = 0;i<sz;i++) cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
656 KB |
Output is correct |
17 |
Correct |
2 ms |
656 KB |
Output is correct |
18 |
Correct |
2 ms |
656 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
656 KB |
Output is correct |
17 |
Correct |
2 ms |
656 KB |
Output is correct |
18 |
Correct |
2 ms |
656 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
3 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
4 ms |
720 KB |
Output is correct |
25 |
Correct |
4 ms |
784 KB |
Output is correct |
26 |
Correct |
5 ms |
788 KB |
Output is correct |
27 |
Correct |
4 ms |
788 KB |
Output is correct |
28 |
Correct |
4 ms |
788 KB |
Output is correct |
29 |
Correct |
5 ms |
788 KB |
Output is correct |
30 |
Correct |
2 ms |
788 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
4 ms |
800 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
3 ms |
800 KB |
Output is correct |
35 |
Correct |
4 ms |
800 KB |
Output is correct |
36 |
Correct |
4 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
656 KB |
Output is correct |
17 |
Correct |
2 ms |
656 KB |
Output is correct |
18 |
Correct |
2 ms |
656 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
3 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
4 ms |
720 KB |
Output is correct |
25 |
Correct |
4 ms |
784 KB |
Output is correct |
26 |
Correct |
5 ms |
788 KB |
Output is correct |
27 |
Correct |
4 ms |
788 KB |
Output is correct |
28 |
Correct |
4 ms |
788 KB |
Output is correct |
29 |
Correct |
5 ms |
788 KB |
Output is correct |
30 |
Correct |
2 ms |
788 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
4 ms |
800 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
3 ms |
800 KB |
Output is correct |
35 |
Correct |
4 ms |
800 KB |
Output is correct |
36 |
Correct |
4 ms |
800 KB |
Output is correct |
37 |
Correct |
15 ms |
956 KB |
Output is correct |
38 |
Correct |
18 ms |
956 KB |
Output is correct |
39 |
Correct |
28 ms |
1084 KB |
Output is correct |
40 |
Correct |
34 ms |
1100 KB |
Output is correct |
41 |
Correct |
37 ms |
1372 KB |
Output is correct |
42 |
Correct |
29 ms |
1372 KB |
Output is correct |
43 |
Correct |
46 ms |
1576 KB |
Output is correct |
44 |
Correct |
46 ms |
1588 KB |
Output is correct |
45 |
Correct |
45 ms |
1588 KB |
Output is correct |
46 |
Correct |
8 ms |
1588 KB |
Output is correct |
47 |
Correct |
32 ms |
1588 KB |
Output is correct |
48 |
Correct |
55 ms |
1588 KB |
Output is correct |
49 |
Correct |
35 ms |
1588 KB |
Output is correct |
50 |
Correct |
33 ms |
1588 KB |
Output is correct |
51 |
Correct |
7 ms |
1588 KB |
Output is correct |
52 |
Correct |
57 ms |
1708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
656 KB |
Output is correct |
17 |
Correct |
2 ms |
656 KB |
Output is correct |
18 |
Correct |
2 ms |
656 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
3 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
4 ms |
720 KB |
Output is correct |
25 |
Correct |
4 ms |
784 KB |
Output is correct |
26 |
Correct |
5 ms |
788 KB |
Output is correct |
27 |
Correct |
4 ms |
788 KB |
Output is correct |
28 |
Correct |
4 ms |
788 KB |
Output is correct |
29 |
Correct |
5 ms |
788 KB |
Output is correct |
30 |
Correct |
2 ms |
788 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
4 ms |
800 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
3 ms |
800 KB |
Output is correct |
35 |
Correct |
4 ms |
800 KB |
Output is correct |
36 |
Correct |
4 ms |
800 KB |
Output is correct |
37 |
Correct |
15 ms |
956 KB |
Output is correct |
38 |
Correct |
18 ms |
956 KB |
Output is correct |
39 |
Correct |
28 ms |
1084 KB |
Output is correct |
40 |
Correct |
34 ms |
1100 KB |
Output is correct |
41 |
Correct |
37 ms |
1372 KB |
Output is correct |
42 |
Correct |
29 ms |
1372 KB |
Output is correct |
43 |
Correct |
46 ms |
1576 KB |
Output is correct |
44 |
Correct |
46 ms |
1588 KB |
Output is correct |
45 |
Correct |
45 ms |
1588 KB |
Output is correct |
46 |
Correct |
8 ms |
1588 KB |
Output is correct |
47 |
Correct |
32 ms |
1588 KB |
Output is correct |
48 |
Correct |
55 ms |
1588 KB |
Output is correct |
49 |
Correct |
35 ms |
1588 KB |
Output is correct |
50 |
Correct |
33 ms |
1588 KB |
Output is correct |
51 |
Correct |
7 ms |
1588 KB |
Output is correct |
52 |
Correct |
57 ms |
1708 KB |
Output is correct |
53 |
Correct |
49 ms |
1708 KB |
Output is correct |
54 |
Correct |
67 ms |
1708 KB |
Output is correct |
55 |
Correct |
113 ms |
2184 KB |
Output is correct |
56 |
Correct |
64 ms |
2184 KB |
Output is correct |
57 |
Correct |
123 ms |
2336 KB |
Output is correct |
58 |
Correct |
79 ms |
2336 KB |
Output is correct |
59 |
Correct |
90 ms |
2336 KB |
Output is correct |
60 |
Correct |
16 ms |
2336 KB |
Output is correct |
61 |
Correct |
113 ms |
2336 KB |
Output is correct |
62 |
Correct |
117 ms |
2336 KB |
Output is correct |
63 |
Correct |
101 ms |
2336 KB |
Output is correct |
64 |
Correct |
99 ms |
2336 KB |
Output is correct |
65 |
Correct |
28 ms |
2336 KB |
Output is correct |
66 |
Correct |
32 ms |
2336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
656 KB |
Output is correct |
13 |
Correct |
2 ms |
656 KB |
Output is correct |
14 |
Correct |
2 ms |
656 KB |
Output is correct |
15 |
Correct |
2 ms |
656 KB |
Output is correct |
16 |
Correct |
2 ms |
656 KB |
Output is correct |
17 |
Correct |
2 ms |
656 KB |
Output is correct |
18 |
Correct |
2 ms |
656 KB |
Output is correct |
19 |
Correct |
2 ms |
708 KB |
Output is correct |
20 |
Correct |
2 ms |
708 KB |
Output is correct |
21 |
Correct |
3 ms |
708 KB |
Output is correct |
22 |
Correct |
3 ms |
720 KB |
Output is correct |
23 |
Correct |
2 ms |
720 KB |
Output is correct |
24 |
Correct |
4 ms |
720 KB |
Output is correct |
25 |
Correct |
4 ms |
784 KB |
Output is correct |
26 |
Correct |
5 ms |
788 KB |
Output is correct |
27 |
Correct |
4 ms |
788 KB |
Output is correct |
28 |
Correct |
4 ms |
788 KB |
Output is correct |
29 |
Correct |
5 ms |
788 KB |
Output is correct |
30 |
Correct |
2 ms |
788 KB |
Output is correct |
31 |
Correct |
5 ms |
800 KB |
Output is correct |
32 |
Correct |
4 ms |
800 KB |
Output is correct |
33 |
Correct |
5 ms |
800 KB |
Output is correct |
34 |
Correct |
3 ms |
800 KB |
Output is correct |
35 |
Correct |
4 ms |
800 KB |
Output is correct |
36 |
Correct |
4 ms |
800 KB |
Output is correct |
37 |
Correct |
15 ms |
956 KB |
Output is correct |
38 |
Correct |
18 ms |
956 KB |
Output is correct |
39 |
Correct |
28 ms |
1084 KB |
Output is correct |
40 |
Correct |
34 ms |
1100 KB |
Output is correct |
41 |
Correct |
37 ms |
1372 KB |
Output is correct |
42 |
Correct |
29 ms |
1372 KB |
Output is correct |
43 |
Correct |
46 ms |
1576 KB |
Output is correct |
44 |
Correct |
46 ms |
1588 KB |
Output is correct |
45 |
Correct |
45 ms |
1588 KB |
Output is correct |
46 |
Correct |
8 ms |
1588 KB |
Output is correct |
47 |
Correct |
32 ms |
1588 KB |
Output is correct |
48 |
Correct |
55 ms |
1588 KB |
Output is correct |
49 |
Correct |
35 ms |
1588 KB |
Output is correct |
50 |
Correct |
33 ms |
1588 KB |
Output is correct |
51 |
Correct |
7 ms |
1588 KB |
Output is correct |
52 |
Correct |
57 ms |
1708 KB |
Output is correct |
53 |
Correct |
49 ms |
1708 KB |
Output is correct |
54 |
Correct |
67 ms |
1708 KB |
Output is correct |
55 |
Correct |
113 ms |
2184 KB |
Output is correct |
56 |
Correct |
64 ms |
2184 KB |
Output is correct |
57 |
Correct |
123 ms |
2336 KB |
Output is correct |
58 |
Correct |
79 ms |
2336 KB |
Output is correct |
59 |
Correct |
90 ms |
2336 KB |
Output is correct |
60 |
Correct |
16 ms |
2336 KB |
Output is correct |
61 |
Correct |
113 ms |
2336 KB |
Output is correct |
62 |
Correct |
117 ms |
2336 KB |
Output is correct |
63 |
Correct |
101 ms |
2336 KB |
Output is correct |
64 |
Correct |
99 ms |
2336 KB |
Output is correct |
65 |
Correct |
28 ms |
2336 KB |
Output is correct |
66 |
Correct |
32 ms |
2336 KB |
Output is correct |
67 |
Correct |
119 ms |
2336 KB |
Output is correct |
68 |
Correct |
41 ms |
2336 KB |
Output is correct |
69 |
Correct |
314 ms |
3732 KB |
Output is correct |
70 |
Correct |
245 ms |
3732 KB |
Output is correct |
71 |
Correct |
216 ms |
3732 KB |
Output is correct |
72 |
Correct |
61 ms |
3732 KB |
Output is correct |
73 |
Correct |
45 ms |
3732 KB |
Output is correct |
74 |
Correct |
333 ms |
3888 KB |
Output is correct |
75 |
Correct |
309 ms |
3888 KB |
Output is correct |
76 |
Correct |
335 ms |
4004 KB |
Output is correct |
77 |
Correct |
342 ms |
4008 KB |
Output is correct |