/* 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;
map<int,int>mp,mp1;
map<int,int>::iterator it;
int main()
{
FAST_READ;
int n;
cin>>n;
int a[n];
for (int i = 0;i<n;i++)cin>>a[i] , sum += a[i];
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++) {
mx = -1;
int oldsum = sum;
sum -= a[no - 1];
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] && mp1[abs(i - (sum - i))] != no) {
//cout<<i<<" "<<abs(i - (sum - i))<<endl;
mp1[abs(i - (sum - i))] = no;
mp[abs(i - (sum - i))]++;
mx = max(mx,mp[abs(i - (sum - i))]);
}
}
if (mx < no) {
cout<<0<<endl;
return 0;
}
sum = oldsum;
for (int i = sum;i>=a[no - 1];i--)
dp[i] += dp[i - a[no - 1]];
}
vector<int>ans;
for (it = mp.begin();it != mp.end();it++)
if ((*it).second == n) ans.push_back((*it).first);
int sz = ans.size();
if (sz == 0)cout<<0<<endl;
else {
cout<<sz<<endl;
for (int i = 0;i<sz;i++) cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
3 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
776 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
2 ms |
804 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
804 KB |
Output is correct |
20 |
Correct |
2 ms |
804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
3 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
776 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
2 ms |
804 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
804 KB |
Output is correct |
20 |
Correct |
2 ms |
804 KB |
Output is correct |
21 |
Correct |
39 ms |
968 KB |
Output is correct |
22 |
Correct |
47 ms |
968 KB |
Output is correct |
23 |
Correct |
22 ms |
968 KB |
Output is correct |
24 |
Correct |
76 ms |
1016 KB |
Output is correct |
25 |
Correct |
117 ms |
1148 KB |
Output is correct |
26 |
Correct |
136 ms |
1152 KB |
Output is correct |
27 |
Correct |
75 ms |
1152 KB |
Output is correct |
28 |
Correct |
64 ms |
1152 KB |
Output is correct |
29 |
Correct |
87 ms |
1164 KB |
Output is correct |
30 |
Correct |
7 ms |
1396 KB |
Output is correct |
31 |
Correct |
128 ms |
1396 KB |
Output is correct |
32 |
Correct |
88 ms |
1396 KB |
Output is correct |
33 |
Correct |
6 ms |
1396 KB |
Output is correct |
34 |
Correct |
6 ms |
1396 KB |
Output is correct |
35 |
Correct |
79 ms |
1396 KB |
Output is correct |
36 |
Correct |
82 ms |
1396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
3 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
776 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
2 ms |
804 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
804 KB |
Output is correct |
20 |
Correct |
2 ms |
804 KB |
Output is correct |
21 |
Correct |
39 ms |
968 KB |
Output is correct |
22 |
Correct |
47 ms |
968 KB |
Output is correct |
23 |
Correct |
22 ms |
968 KB |
Output is correct |
24 |
Correct |
76 ms |
1016 KB |
Output is correct |
25 |
Correct |
117 ms |
1148 KB |
Output is correct |
26 |
Correct |
136 ms |
1152 KB |
Output is correct |
27 |
Correct |
75 ms |
1152 KB |
Output is correct |
28 |
Correct |
64 ms |
1152 KB |
Output is correct |
29 |
Correct |
87 ms |
1164 KB |
Output is correct |
30 |
Correct |
7 ms |
1396 KB |
Output is correct |
31 |
Correct |
128 ms |
1396 KB |
Output is correct |
32 |
Correct |
88 ms |
1396 KB |
Output is correct |
33 |
Correct |
6 ms |
1396 KB |
Output is correct |
34 |
Correct |
6 ms |
1396 KB |
Output is correct |
35 |
Correct |
79 ms |
1396 KB |
Output is correct |
36 |
Correct |
82 ms |
1396 KB |
Output is correct |
37 |
Correct |
731 ms |
1960 KB |
Output is correct |
38 |
Correct |
747 ms |
2028 KB |
Output is correct |
39 |
Correct |
71 ms |
2028 KB |
Output is correct |
40 |
Execution timed out |
1059 ms |
2544 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
3 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
776 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
2 ms |
804 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
804 KB |
Output is correct |
20 |
Correct |
2 ms |
804 KB |
Output is correct |
21 |
Correct |
39 ms |
968 KB |
Output is correct |
22 |
Correct |
47 ms |
968 KB |
Output is correct |
23 |
Correct |
22 ms |
968 KB |
Output is correct |
24 |
Correct |
76 ms |
1016 KB |
Output is correct |
25 |
Correct |
117 ms |
1148 KB |
Output is correct |
26 |
Correct |
136 ms |
1152 KB |
Output is correct |
27 |
Correct |
75 ms |
1152 KB |
Output is correct |
28 |
Correct |
64 ms |
1152 KB |
Output is correct |
29 |
Correct |
87 ms |
1164 KB |
Output is correct |
30 |
Correct |
7 ms |
1396 KB |
Output is correct |
31 |
Correct |
128 ms |
1396 KB |
Output is correct |
32 |
Correct |
88 ms |
1396 KB |
Output is correct |
33 |
Correct |
6 ms |
1396 KB |
Output is correct |
34 |
Correct |
6 ms |
1396 KB |
Output is correct |
35 |
Correct |
79 ms |
1396 KB |
Output is correct |
36 |
Correct |
82 ms |
1396 KB |
Output is correct |
37 |
Correct |
731 ms |
1960 KB |
Output is correct |
38 |
Correct |
747 ms |
2028 KB |
Output is correct |
39 |
Correct |
71 ms |
2028 KB |
Output is correct |
40 |
Execution timed out |
1059 ms |
2544 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
476 KB |
Output is correct |
5 |
Correct |
3 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
600 KB |
Output is correct |
8 |
Correct |
3 ms |
600 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
2 ms |
600 KB |
Output is correct |
11 |
Correct |
3 ms |
728 KB |
Output is correct |
12 |
Correct |
2 ms |
728 KB |
Output is correct |
13 |
Correct |
2 ms |
728 KB |
Output is correct |
14 |
Correct |
3 ms |
728 KB |
Output is correct |
15 |
Correct |
3 ms |
776 KB |
Output is correct |
16 |
Correct |
3 ms |
804 KB |
Output is correct |
17 |
Correct |
2 ms |
804 KB |
Output is correct |
18 |
Correct |
3 ms |
804 KB |
Output is correct |
19 |
Correct |
2 ms |
804 KB |
Output is correct |
20 |
Correct |
2 ms |
804 KB |
Output is correct |
21 |
Correct |
39 ms |
968 KB |
Output is correct |
22 |
Correct |
47 ms |
968 KB |
Output is correct |
23 |
Correct |
22 ms |
968 KB |
Output is correct |
24 |
Correct |
76 ms |
1016 KB |
Output is correct |
25 |
Correct |
117 ms |
1148 KB |
Output is correct |
26 |
Correct |
136 ms |
1152 KB |
Output is correct |
27 |
Correct |
75 ms |
1152 KB |
Output is correct |
28 |
Correct |
64 ms |
1152 KB |
Output is correct |
29 |
Correct |
87 ms |
1164 KB |
Output is correct |
30 |
Correct |
7 ms |
1396 KB |
Output is correct |
31 |
Correct |
128 ms |
1396 KB |
Output is correct |
32 |
Correct |
88 ms |
1396 KB |
Output is correct |
33 |
Correct |
6 ms |
1396 KB |
Output is correct |
34 |
Correct |
6 ms |
1396 KB |
Output is correct |
35 |
Correct |
79 ms |
1396 KB |
Output is correct |
36 |
Correct |
82 ms |
1396 KB |
Output is correct |
37 |
Correct |
731 ms |
1960 KB |
Output is correct |
38 |
Correct |
747 ms |
2028 KB |
Output is correct |
39 |
Correct |
71 ms |
2028 KB |
Output is correct |
40 |
Execution timed out |
1059 ms |
2544 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |