/* 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 dp[250005] , f;
int sum;
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] = true;
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++) {
int oldsum = sum;
sum -= a[no - 1];
memset(dp,0,sizeof(dp));
dp[0] = true;
for (int i = 0;i<n;i++) {
if (i == no - 1)continue;
for (int j = sum;j >= a[i];j--)
dp[j] |= dp[j - a[i]];
}
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))]++;
}
}
sum = oldsum;
}
vector<int>ans;
for (it = mp.begin();it != mp.end();it++)
if ((*it).second == n) ans.push_back((*it).first);
if (ans.size() == 0)cout<<0<<endl;
else {
cout<<ans.size()<<endl;
for (int i = 0;i<ans.size();i++) cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:75:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0;i<ans.size();i++) cout<<ans[i]<<" ";
~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
1088 KB |
Output is correct |
11 |
Correct |
4 ms |
1088 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1088 KB |
Output is correct |
14 |
Correct |
4 ms |
1088 KB |
Output is correct |
15 |
Correct |
3 ms |
1088 KB |
Output is correct |
16 |
Correct |
4 ms |
1088 KB |
Output is correct |
17 |
Correct |
3 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1088 KB |
Output is correct |
20 |
Correct |
3 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
1088 KB |
Output is correct |
11 |
Correct |
4 ms |
1088 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1088 KB |
Output is correct |
14 |
Correct |
4 ms |
1088 KB |
Output is correct |
15 |
Correct |
3 ms |
1088 KB |
Output is correct |
16 |
Correct |
4 ms |
1088 KB |
Output is correct |
17 |
Correct |
3 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1088 KB |
Output is correct |
20 |
Correct |
3 ms |
1088 KB |
Output is correct |
21 |
Correct |
39 ms |
1200 KB |
Output is correct |
22 |
Correct |
51 ms |
1200 KB |
Output is correct |
23 |
Correct |
22 ms |
1200 KB |
Output is correct |
24 |
Correct |
94 ms |
1324 KB |
Output is correct |
25 |
Correct |
174 ms |
1508 KB |
Output is correct |
26 |
Correct |
190 ms |
1656 KB |
Output is correct |
27 |
Correct |
127 ms |
1656 KB |
Output is correct |
28 |
Correct |
128 ms |
1656 KB |
Output is correct |
29 |
Correct |
144 ms |
1656 KB |
Output is correct |
30 |
Correct |
121 ms |
1656 KB |
Output is correct |
31 |
Correct |
160 ms |
1656 KB |
Output is correct |
32 |
Correct |
104 ms |
1656 KB |
Output is correct |
33 |
Correct |
86 ms |
1656 KB |
Output is correct |
34 |
Correct |
86 ms |
1656 KB |
Output is correct |
35 |
Correct |
137 ms |
1656 KB |
Output is correct |
36 |
Correct |
103 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
1088 KB |
Output is correct |
11 |
Correct |
4 ms |
1088 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1088 KB |
Output is correct |
14 |
Correct |
4 ms |
1088 KB |
Output is correct |
15 |
Correct |
3 ms |
1088 KB |
Output is correct |
16 |
Correct |
4 ms |
1088 KB |
Output is correct |
17 |
Correct |
3 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1088 KB |
Output is correct |
20 |
Correct |
3 ms |
1088 KB |
Output is correct |
21 |
Correct |
39 ms |
1200 KB |
Output is correct |
22 |
Correct |
51 ms |
1200 KB |
Output is correct |
23 |
Correct |
22 ms |
1200 KB |
Output is correct |
24 |
Correct |
94 ms |
1324 KB |
Output is correct |
25 |
Correct |
174 ms |
1508 KB |
Output is correct |
26 |
Correct |
190 ms |
1656 KB |
Output is correct |
27 |
Correct |
127 ms |
1656 KB |
Output is correct |
28 |
Correct |
128 ms |
1656 KB |
Output is correct |
29 |
Correct |
144 ms |
1656 KB |
Output is correct |
30 |
Correct |
121 ms |
1656 KB |
Output is correct |
31 |
Correct |
160 ms |
1656 KB |
Output is correct |
32 |
Correct |
104 ms |
1656 KB |
Output is correct |
33 |
Correct |
86 ms |
1656 KB |
Output is correct |
34 |
Correct |
86 ms |
1656 KB |
Output is correct |
35 |
Correct |
137 ms |
1656 KB |
Output is correct |
36 |
Correct |
103 ms |
1656 KB |
Output is correct |
37 |
Execution timed out |
1078 ms |
2100 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
1088 KB |
Output is correct |
11 |
Correct |
4 ms |
1088 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1088 KB |
Output is correct |
14 |
Correct |
4 ms |
1088 KB |
Output is correct |
15 |
Correct |
3 ms |
1088 KB |
Output is correct |
16 |
Correct |
4 ms |
1088 KB |
Output is correct |
17 |
Correct |
3 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1088 KB |
Output is correct |
20 |
Correct |
3 ms |
1088 KB |
Output is correct |
21 |
Correct |
39 ms |
1200 KB |
Output is correct |
22 |
Correct |
51 ms |
1200 KB |
Output is correct |
23 |
Correct |
22 ms |
1200 KB |
Output is correct |
24 |
Correct |
94 ms |
1324 KB |
Output is correct |
25 |
Correct |
174 ms |
1508 KB |
Output is correct |
26 |
Correct |
190 ms |
1656 KB |
Output is correct |
27 |
Correct |
127 ms |
1656 KB |
Output is correct |
28 |
Correct |
128 ms |
1656 KB |
Output is correct |
29 |
Correct |
144 ms |
1656 KB |
Output is correct |
30 |
Correct |
121 ms |
1656 KB |
Output is correct |
31 |
Correct |
160 ms |
1656 KB |
Output is correct |
32 |
Correct |
104 ms |
1656 KB |
Output is correct |
33 |
Correct |
86 ms |
1656 KB |
Output is correct |
34 |
Correct |
86 ms |
1656 KB |
Output is correct |
35 |
Correct |
137 ms |
1656 KB |
Output is correct |
36 |
Correct |
103 ms |
1656 KB |
Output is correct |
37 |
Execution timed out |
1078 ms |
2100 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
556 KB |
Output is correct |
3 |
Correct |
2 ms |
556 KB |
Output is correct |
4 |
Correct |
2 ms |
656 KB |
Output is correct |
5 |
Correct |
3 ms |
916 KB |
Output is correct |
6 |
Correct |
2 ms |
928 KB |
Output is correct |
7 |
Correct |
2 ms |
928 KB |
Output is correct |
8 |
Correct |
3 ms |
1088 KB |
Output is correct |
9 |
Correct |
3 ms |
1088 KB |
Output is correct |
10 |
Correct |
4 ms |
1088 KB |
Output is correct |
11 |
Correct |
4 ms |
1088 KB |
Output is correct |
12 |
Correct |
3 ms |
1088 KB |
Output is correct |
13 |
Correct |
4 ms |
1088 KB |
Output is correct |
14 |
Correct |
4 ms |
1088 KB |
Output is correct |
15 |
Correct |
3 ms |
1088 KB |
Output is correct |
16 |
Correct |
4 ms |
1088 KB |
Output is correct |
17 |
Correct |
3 ms |
1088 KB |
Output is correct |
18 |
Correct |
3 ms |
1088 KB |
Output is correct |
19 |
Correct |
3 ms |
1088 KB |
Output is correct |
20 |
Correct |
3 ms |
1088 KB |
Output is correct |
21 |
Correct |
39 ms |
1200 KB |
Output is correct |
22 |
Correct |
51 ms |
1200 KB |
Output is correct |
23 |
Correct |
22 ms |
1200 KB |
Output is correct |
24 |
Correct |
94 ms |
1324 KB |
Output is correct |
25 |
Correct |
174 ms |
1508 KB |
Output is correct |
26 |
Correct |
190 ms |
1656 KB |
Output is correct |
27 |
Correct |
127 ms |
1656 KB |
Output is correct |
28 |
Correct |
128 ms |
1656 KB |
Output is correct |
29 |
Correct |
144 ms |
1656 KB |
Output is correct |
30 |
Correct |
121 ms |
1656 KB |
Output is correct |
31 |
Correct |
160 ms |
1656 KB |
Output is correct |
32 |
Correct |
104 ms |
1656 KB |
Output is correct |
33 |
Correct |
86 ms |
1656 KB |
Output is correct |
34 |
Correct |
86 ms |
1656 KB |
Output is correct |
35 |
Correct |
137 ms |
1656 KB |
Output is correct |
36 |
Correct |
103 ms |
1656 KB |
Output is correct |
37 |
Execution timed out |
1078 ms |
2100 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |