#include <bits/stdc++.h>
using namespace std;
int ct[250005],n,a[505],sum;
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;
for (int j=1;j<=n;j++){
if (j != i){
for (int k=j*500;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<=n*500;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<=n*500;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:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | 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 |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
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 |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
360 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
360 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
6 ms |
332 KB |
Output is correct |
21 |
Correct |
52 ms |
384 KB |
Output is correct |
22 |
Correct |
79 ms |
400 KB |
Output is correct |
23 |
Correct |
29 ms |
452 KB |
Output is correct |
24 |
Correct |
156 ms |
424 KB |
Output is correct |
25 |
Correct |
158 ms |
432 KB |
Output is correct |
26 |
Correct |
185 ms |
444 KB |
Output is correct |
27 |
Correct |
186 ms |
460 KB |
Output is correct |
28 |
Correct |
199 ms |
476 KB |
Output is correct |
29 |
Correct |
184 ms |
460 KB |
Output is correct |
30 |
Correct |
188 ms |
424 KB |
Output is correct |
31 |
Correct |
187 ms |
436 KB |
Output is correct |
32 |
Correct |
182 ms |
452 KB |
Output is correct |
33 |
Correct |
184 ms |
460 KB |
Output is correct |
34 |
Correct |
186 ms |
460 KB |
Output is correct |
35 |
Correct |
184 ms |
460 KB |
Output is correct |
36 |
Correct |
204 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
360 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
6 ms |
332 KB |
Output is correct |
21 |
Correct |
52 ms |
384 KB |
Output is correct |
22 |
Correct |
79 ms |
400 KB |
Output is correct |
23 |
Correct |
29 ms |
452 KB |
Output is correct |
24 |
Correct |
156 ms |
424 KB |
Output is correct |
25 |
Correct |
158 ms |
432 KB |
Output is correct |
26 |
Correct |
185 ms |
444 KB |
Output is correct |
27 |
Correct |
186 ms |
460 KB |
Output is correct |
28 |
Correct |
199 ms |
476 KB |
Output is correct |
29 |
Correct |
184 ms |
460 KB |
Output is correct |
30 |
Correct |
188 ms |
424 KB |
Output is correct |
31 |
Correct |
187 ms |
436 KB |
Output is correct |
32 |
Correct |
182 ms |
452 KB |
Output is correct |
33 |
Correct |
184 ms |
460 KB |
Output is correct |
34 |
Correct |
186 ms |
460 KB |
Output is correct |
35 |
Correct |
184 ms |
460 KB |
Output is correct |
36 |
Correct |
204 ms |
436 KB |
Output is correct |
37 |
Execution timed out |
1084 ms |
524 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
360 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
6 ms |
332 KB |
Output is correct |
21 |
Correct |
52 ms |
384 KB |
Output is correct |
22 |
Correct |
79 ms |
400 KB |
Output is correct |
23 |
Correct |
29 ms |
452 KB |
Output is correct |
24 |
Correct |
156 ms |
424 KB |
Output is correct |
25 |
Correct |
158 ms |
432 KB |
Output is correct |
26 |
Correct |
185 ms |
444 KB |
Output is correct |
27 |
Correct |
186 ms |
460 KB |
Output is correct |
28 |
Correct |
199 ms |
476 KB |
Output is correct |
29 |
Correct |
184 ms |
460 KB |
Output is correct |
30 |
Correct |
188 ms |
424 KB |
Output is correct |
31 |
Correct |
187 ms |
436 KB |
Output is correct |
32 |
Correct |
182 ms |
452 KB |
Output is correct |
33 |
Correct |
184 ms |
460 KB |
Output is correct |
34 |
Correct |
186 ms |
460 KB |
Output is correct |
35 |
Correct |
184 ms |
460 KB |
Output is correct |
36 |
Correct |
204 ms |
436 KB |
Output is correct |
37 |
Execution timed out |
1084 ms |
524 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
360 KB |
Output is correct |
14 |
Correct |
5 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
332 KB |
Output is correct |
20 |
Correct |
6 ms |
332 KB |
Output is correct |
21 |
Correct |
52 ms |
384 KB |
Output is correct |
22 |
Correct |
79 ms |
400 KB |
Output is correct |
23 |
Correct |
29 ms |
452 KB |
Output is correct |
24 |
Correct |
156 ms |
424 KB |
Output is correct |
25 |
Correct |
158 ms |
432 KB |
Output is correct |
26 |
Correct |
185 ms |
444 KB |
Output is correct |
27 |
Correct |
186 ms |
460 KB |
Output is correct |
28 |
Correct |
199 ms |
476 KB |
Output is correct |
29 |
Correct |
184 ms |
460 KB |
Output is correct |
30 |
Correct |
188 ms |
424 KB |
Output is correct |
31 |
Correct |
187 ms |
436 KB |
Output is correct |
32 |
Correct |
182 ms |
452 KB |
Output is correct |
33 |
Correct |
184 ms |
460 KB |
Output is correct |
34 |
Correct |
186 ms |
460 KB |
Output is correct |
35 |
Correct |
184 ms |
460 KB |
Output is correct |
36 |
Correct |
204 ms |
436 KB |
Output is correct |
37 |
Execution timed out |
1084 ms |
524 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |