#include <bits/stdc++.h>
#define pb push_back
#define LINE "-------------------\n"
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int N = 500+1;
const int M = 500*500+1;
vector <int> ans;
int n, m, nums[N];
const ll MOD = 1e9+7;
ll dp[M], dp1[M], sum;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
for (int i = 1; i <= n; i++) cin >> nums[i];
dp[0] = 1;
for (int i = 1; i <= n; i++) {
int& x = nums[i];
sum += x;
for (int j = M-1; j >= x; j--)
dp[j] = (dp[j] + dp[j-x]) % MOD;
}
if (sum & 1 || dp[sum / 2] == 0) {
cout << "0\n";
return 0;
}
for (int i = 1; i <= n; i++) {
int& x = nums[i];
for (int j = x; j <= M-1; j++)
dp[j] = (dp[j] - dp[j-x] + MOD) % MOD;
for (int j = M-1; j >= 0; j--)
if (dp[j] > 0 && 2 * j + x - sum >= 0) dp1[2 * j + x - sum]++;
for (int j = M-1; j >= x; j--)
dp[j] = (dp[j] + dp[j-x]) % MOD;
}
for (int j = 0; j < M; j++) {
if (dp1[j] == n) ans.pb(j);
}
cout << sz(ans) << '\n';
for (auto&el:ans) cout << el << ' '; cout << '\n';
}
Compilation message
bootfall.cpp: In function 'int main()':
bootfall.cpp:47:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
47 | for (auto&el:ans) cout << el << ' '; cout << '\n';
| ^~~
bootfall.cpp:47:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
47 | for (auto&el:ans) cout << el << ' '; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
10 |
Correct |
40 ms |
2252 KB |
Output is correct |
11 |
Correct |
58 ms |
2256 KB |
Output is correct |
12 |
Correct |
44 ms |
2272 KB |
Output is correct |
13 |
Correct |
40 ms |
2256 KB |
Output is correct |
14 |
Correct |
47 ms |
2252 KB |
Output is correct |
15 |
Correct |
50 ms |
2252 KB |
Output is correct |
16 |
Correct |
53 ms |
2252 KB |
Output is correct |
17 |
Correct |
29 ms |
2276 KB |
Output is correct |
18 |
Correct |
34 ms |
2252 KB |
Output is correct |
19 |
Correct |
38 ms |
2260 KB |
Output is correct |
20 |
Correct |
40 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
10 |
Correct |
40 ms |
2252 KB |
Output is correct |
11 |
Correct |
58 ms |
2256 KB |
Output is correct |
12 |
Correct |
44 ms |
2272 KB |
Output is correct |
13 |
Correct |
40 ms |
2256 KB |
Output is correct |
14 |
Correct |
47 ms |
2252 KB |
Output is correct |
15 |
Correct |
50 ms |
2252 KB |
Output is correct |
16 |
Correct |
53 ms |
2252 KB |
Output is correct |
17 |
Correct |
29 ms |
2276 KB |
Output is correct |
18 |
Correct |
34 ms |
2252 KB |
Output is correct |
19 |
Correct |
38 ms |
2260 KB |
Output is correct |
20 |
Correct |
40 ms |
2252 KB |
Output is correct |
21 |
Correct |
86 ms |
2280 KB |
Output is correct |
22 |
Correct |
98 ms |
2276 KB |
Output is correct |
23 |
Correct |
71 ms |
2252 KB |
Output is correct |
24 |
Correct |
126 ms |
2280 KB |
Output is correct |
25 |
Correct |
125 ms |
2324 KB |
Output is correct |
26 |
Correct |
133 ms |
2324 KB |
Output is correct |
27 |
Correct |
130 ms |
2264 KB |
Output is correct |
28 |
Correct |
131 ms |
2268 KB |
Output is correct |
29 |
Correct |
136 ms |
2336 KB |
Output is correct |
30 |
Correct |
134 ms |
2252 KB |
Output is correct |
31 |
Correct |
133 ms |
2372 KB |
Output is correct |
32 |
Correct |
149 ms |
2292 KB |
Output is correct |
33 |
Correct |
135 ms |
2384 KB |
Output is correct |
34 |
Correct |
149 ms |
2252 KB |
Output is correct |
35 |
Correct |
142 ms |
2264 KB |
Output is correct |
36 |
Correct |
138 ms |
2292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
10 |
Correct |
40 ms |
2252 KB |
Output is correct |
11 |
Correct |
58 ms |
2256 KB |
Output is correct |
12 |
Correct |
44 ms |
2272 KB |
Output is correct |
13 |
Correct |
40 ms |
2256 KB |
Output is correct |
14 |
Correct |
47 ms |
2252 KB |
Output is correct |
15 |
Correct |
50 ms |
2252 KB |
Output is correct |
16 |
Correct |
53 ms |
2252 KB |
Output is correct |
17 |
Correct |
29 ms |
2276 KB |
Output is correct |
18 |
Correct |
34 ms |
2252 KB |
Output is correct |
19 |
Correct |
38 ms |
2260 KB |
Output is correct |
20 |
Correct |
40 ms |
2252 KB |
Output is correct |
21 |
Correct |
86 ms |
2280 KB |
Output is correct |
22 |
Correct |
98 ms |
2276 KB |
Output is correct |
23 |
Correct |
71 ms |
2252 KB |
Output is correct |
24 |
Correct |
126 ms |
2280 KB |
Output is correct |
25 |
Correct |
125 ms |
2324 KB |
Output is correct |
26 |
Correct |
133 ms |
2324 KB |
Output is correct |
27 |
Correct |
130 ms |
2264 KB |
Output is correct |
28 |
Correct |
131 ms |
2268 KB |
Output is correct |
29 |
Correct |
136 ms |
2336 KB |
Output is correct |
30 |
Correct |
134 ms |
2252 KB |
Output is correct |
31 |
Correct |
133 ms |
2372 KB |
Output is correct |
32 |
Correct |
149 ms |
2292 KB |
Output is correct |
33 |
Correct |
135 ms |
2384 KB |
Output is correct |
34 |
Correct |
149 ms |
2252 KB |
Output is correct |
35 |
Correct |
142 ms |
2264 KB |
Output is correct |
36 |
Correct |
138 ms |
2292 KB |
Output is correct |
37 |
Correct |
265 ms |
2540 KB |
Output is correct |
38 |
Correct |
260 ms |
2544 KB |
Output is correct |
39 |
Correct |
338 ms |
2756 KB |
Output is correct |
40 |
Correct |
356 ms |
2636 KB |
Output is correct |
41 |
Correct |
348 ms |
2792 KB |
Output is correct |
42 |
Correct |
337 ms |
2640 KB |
Output is correct |
43 |
Correct |
319 ms |
3080 KB |
Output is correct |
44 |
Correct |
343 ms |
3160 KB |
Output is correct |
45 |
Correct |
346 ms |
3024 KB |
Output is correct |
46 |
Correct |
352 ms |
2396 KB |
Output is correct |
47 |
Correct |
326 ms |
2628 KB |
Output is correct |
48 |
Correct |
326 ms |
3012 KB |
Output is correct |
49 |
Correct |
331 ms |
2744 KB |
Output is correct |
50 |
Correct |
323 ms |
2652 KB |
Output is correct |
51 |
Correct |
98 ms |
2252 KB |
Output is correct |
52 |
Correct |
367 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
10 |
Correct |
40 ms |
2252 KB |
Output is correct |
11 |
Correct |
58 ms |
2256 KB |
Output is correct |
12 |
Correct |
44 ms |
2272 KB |
Output is correct |
13 |
Correct |
40 ms |
2256 KB |
Output is correct |
14 |
Correct |
47 ms |
2252 KB |
Output is correct |
15 |
Correct |
50 ms |
2252 KB |
Output is correct |
16 |
Correct |
53 ms |
2252 KB |
Output is correct |
17 |
Correct |
29 ms |
2276 KB |
Output is correct |
18 |
Correct |
34 ms |
2252 KB |
Output is correct |
19 |
Correct |
38 ms |
2260 KB |
Output is correct |
20 |
Correct |
40 ms |
2252 KB |
Output is correct |
21 |
Correct |
86 ms |
2280 KB |
Output is correct |
22 |
Correct |
98 ms |
2276 KB |
Output is correct |
23 |
Correct |
71 ms |
2252 KB |
Output is correct |
24 |
Correct |
126 ms |
2280 KB |
Output is correct |
25 |
Correct |
125 ms |
2324 KB |
Output is correct |
26 |
Correct |
133 ms |
2324 KB |
Output is correct |
27 |
Correct |
130 ms |
2264 KB |
Output is correct |
28 |
Correct |
131 ms |
2268 KB |
Output is correct |
29 |
Correct |
136 ms |
2336 KB |
Output is correct |
30 |
Correct |
134 ms |
2252 KB |
Output is correct |
31 |
Correct |
133 ms |
2372 KB |
Output is correct |
32 |
Correct |
149 ms |
2292 KB |
Output is correct |
33 |
Correct |
135 ms |
2384 KB |
Output is correct |
34 |
Correct |
149 ms |
2252 KB |
Output is correct |
35 |
Correct |
142 ms |
2264 KB |
Output is correct |
36 |
Correct |
138 ms |
2292 KB |
Output is correct |
37 |
Correct |
265 ms |
2540 KB |
Output is correct |
38 |
Correct |
260 ms |
2544 KB |
Output is correct |
39 |
Correct |
338 ms |
2756 KB |
Output is correct |
40 |
Correct |
356 ms |
2636 KB |
Output is correct |
41 |
Correct |
348 ms |
2792 KB |
Output is correct |
42 |
Correct |
337 ms |
2640 KB |
Output is correct |
43 |
Correct |
319 ms |
3080 KB |
Output is correct |
44 |
Correct |
343 ms |
3160 KB |
Output is correct |
45 |
Correct |
346 ms |
3024 KB |
Output is correct |
46 |
Correct |
352 ms |
2396 KB |
Output is correct |
47 |
Correct |
326 ms |
2628 KB |
Output is correct |
48 |
Correct |
326 ms |
3012 KB |
Output is correct |
49 |
Correct |
331 ms |
2744 KB |
Output is correct |
50 |
Correct |
323 ms |
2652 KB |
Output is correct |
51 |
Correct |
98 ms |
2252 KB |
Output is correct |
52 |
Correct |
367 ms |
3288 KB |
Output is correct |
53 |
Correct |
443 ms |
2868 KB |
Output is correct |
54 |
Correct |
451 ms |
3012 KB |
Output is correct |
55 |
Correct |
484 ms |
3664 KB |
Output is correct |
56 |
Correct |
400 ms |
3076 KB |
Output is correct |
57 |
Correct |
471 ms |
3924 KB |
Output is correct |
58 |
Correct |
463 ms |
3116 KB |
Output is correct |
59 |
Correct |
481 ms |
3368 KB |
Output is correct |
60 |
Correct |
132 ms |
2252 KB |
Output is correct |
61 |
Correct |
463 ms |
3440 KB |
Output is correct |
62 |
Correct |
432 ms |
3520 KB |
Output is correct |
63 |
Correct |
433 ms |
3680 KB |
Output is correct |
64 |
Correct |
473 ms |
3656 KB |
Output is correct |
65 |
Correct |
419 ms |
2632 KB |
Output is correct |
66 |
Correct |
408 ms |
2780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2276 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
3 ms |
2252 KB |
Output is correct |
4 |
Correct |
7 ms |
2252 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
12 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2272 KB |
Output is correct |
8 |
Correct |
18 ms |
2288 KB |
Output is correct |
9 |
Correct |
19 ms |
2276 KB |
Output is correct |
10 |
Correct |
40 ms |
2252 KB |
Output is correct |
11 |
Correct |
58 ms |
2256 KB |
Output is correct |
12 |
Correct |
44 ms |
2272 KB |
Output is correct |
13 |
Correct |
40 ms |
2256 KB |
Output is correct |
14 |
Correct |
47 ms |
2252 KB |
Output is correct |
15 |
Correct |
50 ms |
2252 KB |
Output is correct |
16 |
Correct |
53 ms |
2252 KB |
Output is correct |
17 |
Correct |
29 ms |
2276 KB |
Output is correct |
18 |
Correct |
34 ms |
2252 KB |
Output is correct |
19 |
Correct |
38 ms |
2260 KB |
Output is correct |
20 |
Correct |
40 ms |
2252 KB |
Output is correct |
21 |
Correct |
86 ms |
2280 KB |
Output is correct |
22 |
Correct |
98 ms |
2276 KB |
Output is correct |
23 |
Correct |
71 ms |
2252 KB |
Output is correct |
24 |
Correct |
126 ms |
2280 KB |
Output is correct |
25 |
Correct |
125 ms |
2324 KB |
Output is correct |
26 |
Correct |
133 ms |
2324 KB |
Output is correct |
27 |
Correct |
130 ms |
2264 KB |
Output is correct |
28 |
Correct |
131 ms |
2268 KB |
Output is correct |
29 |
Correct |
136 ms |
2336 KB |
Output is correct |
30 |
Correct |
134 ms |
2252 KB |
Output is correct |
31 |
Correct |
133 ms |
2372 KB |
Output is correct |
32 |
Correct |
149 ms |
2292 KB |
Output is correct |
33 |
Correct |
135 ms |
2384 KB |
Output is correct |
34 |
Correct |
149 ms |
2252 KB |
Output is correct |
35 |
Correct |
142 ms |
2264 KB |
Output is correct |
36 |
Correct |
138 ms |
2292 KB |
Output is correct |
37 |
Correct |
265 ms |
2540 KB |
Output is correct |
38 |
Correct |
260 ms |
2544 KB |
Output is correct |
39 |
Correct |
338 ms |
2756 KB |
Output is correct |
40 |
Correct |
356 ms |
2636 KB |
Output is correct |
41 |
Correct |
348 ms |
2792 KB |
Output is correct |
42 |
Correct |
337 ms |
2640 KB |
Output is correct |
43 |
Correct |
319 ms |
3080 KB |
Output is correct |
44 |
Correct |
343 ms |
3160 KB |
Output is correct |
45 |
Correct |
346 ms |
3024 KB |
Output is correct |
46 |
Correct |
352 ms |
2396 KB |
Output is correct |
47 |
Correct |
326 ms |
2628 KB |
Output is correct |
48 |
Correct |
326 ms |
3012 KB |
Output is correct |
49 |
Correct |
331 ms |
2744 KB |
Output is correct |
50 |
Correct |
323 ms |
2652 KB |
Output is correct |
51 |
Correct |
98 ms |
2252 KB |
Output is correct |
52 |
Correct |
367 ms |
3288 KB |
Output is correct |
53 |
Correct |
443 ms |
2868 KB |
Output is correct |
54 |
Correct |
451 ms |
3012 KB |
Output is correct |
55 |
Correct |
484 ms |
3664 KB |
Output is correct |
56 |
Correct |
400 ms |
3076 KB |
Output is correct |
57 |
Correct |
471 ms |
3924 KB |
Output is correct |
58 |
Correct |
463 ms |
3116 KB |
Output is correct |
59 |
Correct |
481 ms |
3368 KB |
Output is correct |
60 |
Correct |
132 ms |
2252 KB |
Output is correct |
61 |
Correct |
463 ms |
3440 KB |
Output is correct |
62 |
Correct |
432 ms |
3520 KB |
Output is correct |
63 |
Correct |
433 ms |
3680 KB |
Output is correct |
64 |
Correct |
473 ms |
3656 KB |
Output is correct |
65 |
Correct |
419 ms |
2632 KB |
Output is correct |
66 |
Correct |
408 ms |
2780 KB |
Output is correct |
67 |
Correct |
547 ms |
3412 KB |
Output is correct |
68 |
Correct |
196 ms |
2256 KB |
Output is correct |
69 |
Correct |
657 ms |
5056 KB |
Output is correct |
70 |
Correct |
662 ms |
4024 KB |
Output is correct |
71 |
Correct |
662 ms |
3992 KB |
Output is correct |
72 |
Correct |
710 ms |
3228 KB |
Output is correct |
73 |
Correct |
658 ms |
3236 KB |
Output is correct |
74 |
Correct |
662 ms |
5216 KB |
Output is correct |
75 |
Correct |
673 ms |
4636 KB |
Output is correct |
76 |
Correct |
705 ms |
5340 KB |
Output is correct |
77 |
Correct |
688 ms |
5380 KB |
Output is correct |