#include <bits/stdc++.h>
using namespace std;
int ct[250005],n,a[505],sum,now;
bool dp[250005],gg[250005],imp;
vector <int> ans;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i=1;i<=n;i++){
cin >> a[i];
sum+=a[i];
}
for (int i=0;i<=n;i++){
for (int j=1;j<=n*500;j++){
dp[j]=false;
gg[j]=false;
}
dp[0]=true; now=0;
for (int j=1;j<=n;j++){
if (j != i){
now+=a[j];
for (int k=now;k>=a[j];k--){
dp[k]=dp[k]|dp[k-a[j]];
}
}
}
if (i == 0){
if (sum%2 == 1 || !dp[sum/2]) imp=true;
continue;
}
for (int j=0;j<=now;j++){
if (dp[j] && !gg[max(j,sum-j-a[i])-min(j,sum-j-a[i])]){
ct[max(j,sum-j-a[i])-min(j,sum-j-a[i])]++;
gg[max(j,sum-j-a[i])-min(j,sum-j-a[i])]=true;
}
}
}
for (int i=1;i<=sum;i++){
if (ct[i] == n)
ans.push_back(i);
}
if (imp){
cout << "0\n\n";
return 0;
}
cout << (int)ans.size() << "\n";
for (int i=0;i<ans.size();i++){
cout << ans[i] << " ";
}
cout << "\n";
return 0;
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:48:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
6 ms |
332 KB |
Output is correct |
22 |
Correct |
9 ms |
412 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
16 ms |
460 KB |
Output is correct |
25 |
Correct |
33 ms |
440 KB |
Output is correct |
26 |
Correct |
37 ms |
448 KB |
Output is correct |
27 |
Correct |
33 ms |
452 KB |
Output is correct |
28 |
Correct |
36 ms |
460 KB |
Output is correct |
29 |
Correct |
37 ms |
452 KB |
Output is correct |
30 |
Correct |
21 ms |
444 KB |
Output is correct |
31 |
Correct |
30 ms |
452 KB |
Output is correct |
32 |
Correct |
20 ms |
452 KB |
Output is correct |
33 |
Correct |
38 ms |
332 KB |
Output is correct |
34 |
Correct |
36 ms |
460 KB |
Output is correct |
35 |
Correct |
36 ms |
332 KB |
Output is correct |
36 |
Correct |
19 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
6 ms |
332 KB |
Output is correct |
22 |
Correct |
9 ms |
412 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
16 ms |
460 KB |
Output is correct |
25 |
Correct |
33 ms |
440 KB |
Output is correct |
26 |
Correct |
37 ms |
448 KB |
Output is correct |
27 |
Correct |
33 ms |
452 KB |
Output is correct |
28 |
Correct |
36 ms |
460 KB |
Output is correct |
29 |
Correct |
37 ms |
452 KB |
Output is correct |
30 |
Correct |
21 ms |
444 KB |
Output is correct |
31 |
Correct |
30 ms |
452 KB |
Output is correct |
32 |
Correct |
20 ms |
452 KB |
Output is correct |
33 |
Correct |
38 ms |
332 KB |
Output is correct |
34 |
Correct |
36 ms |
460 KB |
Output is correct |
35 |
Correct |
36 ms |
332 KB |
Output is correct |
36 |
Correct |
19 ms |
444 KB |
Output is correct |
37 |
Correct |
310 ms |
692 KB |
Output is correct |
38 |
Correct |
302 ms |
720 KB |
Output is correct |
39 |
Execution timed out |
1091 ms |
716 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
6 ms |
332 KB |
Output is correct |
22 |
Correct |
9 ms |
412 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
16 ms |
460 KB |
Output is correct |
25 |
Correct |
33 ms |
440 KB |
Output is correct |
26 |
Correct |
37 ms |
448 KB |
Output is correct |
27 |
Correct |
33 ms |
452 KB |
Output is correct |
28 |
Correct |
36 ms |
460 KB |
Output is correct |
29 |
Correct |
37 ms |
452 KB |
Output is correct |
30 |
Correct |
21 ms |
444 KB |
Output is correct |
31 |
Correct |
30 ms |
452 KB |
Output is correct |
32 |
Correct |
20 ms |
452 KB |
Output is correct |
33 |
Correct |
38 ms |
332 KB |
Output is correct |
34 |
Correct |
36 ms |
460 KB |
Output is correct |
35 |
Correct |
36 ms |
332 KB |
Output is correct |
36 |
Correct |
19 ms |
444 KB |
Output is correct |
37 |
Correct |
310 ms |
692 KB |
Output is correct |
38 |
Correct |
302 ms |
720 KB |
Output is correct |
39 |
Execution timed out |
1091 ms |
716 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
216 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
6 ms |
332 KB |
Output is correct |
22 |
Correct |
9 ms |
412 KB |
Output is correct |
23 |
Correct |
3 ms |
332 KB |
Output is correct |
24 |
Correct |
16 ms |
460 KB |
Output is correct |
25 |
Correct |
33 ms |
440 KB |
Output is correct |
26 |
Correct |
37 ms |
448 KB |
Output is correct |
27 |
Correct |
33 ms |
452 KB |
Output is correct |
28 |
Correct |
36 ms |
460 KB |
Output is correct |
29 |
Correct |
37 ms |
452 KB |
Output is correct |
30 |
Correct |
21 ms |
444 KB |
Output is correct |
31 |
Correct |
30 ms |
452 KB |
Output is correct |
32 |
Correct |
20 ms |
452 KB |
Output is correct |
33 |
Correct |
38 ms |
332 KB |
Output is correct |
34 |
Correct |
36 ms |
460 KB |
Output is correct |
35 |
Correct |
36 ms |
332 KB |
Output is correct |
36 |
Correct |
19 ms |
444 KB |
Output is correct |
37 |
Correct |
310 ms |
692 KB |
Output is correct |
38 |
Correct |
302 ms |
720 KB |
Output is correct |
39 |
Execution timed out |
1091 ms |
716 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |