#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() {
// 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;
}
// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
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;
/*
left = (sum - x + a) / 2 == j;
sum-x+a = 2j
a = 2j+x-sum;
*/
// cout << LINE;B
// cout << x << ":\n";
// cout << "dp: ";
// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
for (int j = M-1; j >= 0; j--) {
int a = 2 * j + x - sum;
if (dp[j] > 0 && a >= 0) {
// cout << j << " " << a << '\n';
dp1[a]++;
// cout << 2 * j + x - sum << ' ';
}
}
// cout << "\n";
for (int j = M-1; j >= x; j--)
dp[j] = (dp[j] + dp[j-x]) % MOD;
// cout << "dp: ";
// for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10];
}
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:64:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
64 | for (auto&el:ans) cout << el << ' '; cout << '\n';
| ^~~
bootfall.cpp:64:39: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
64 | for (auto&el:ans) cout << el << ' '; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
10 |
Correct |
44 ms |
2340 KB |
Output is correct |
11 |
Correct |
46 ms |
2232 KB |
Output is correct |
12 |
Correct |
47 ms |
2256 KB |
Output is correct |
13 |
Correct |
39 ms |
2252 KB |
Output is correct |
14 |
Correct |
40 ms |
2252 KB |
Output is correct |
15 |
Correct |
45 ms |
2252 KB |
Output is correct |
16 |
Correct |
48 ms |
2252 KB |
Output is correct |
17 |
Correct |
28 ms |
2232 KB |
Output is correct |
18 |
Correct |
35 ms |
2124 KB |
Output is correct |
19 |
Correct |
38 ms |
2252 KB |
Output is correct |
20 |
Correct |
43 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
10 |
Correct |
44 ms |
2340 KB |
Output is correct |
11 |
Correct |
46 ms |
2232 KB |
Output is correct |
12 |
Correct |
47 ms |
2256 KB |
Output is correct |
13 |
Correct |
39 ms |
2252 KB |
Output is correct |
14 |
Correct |
40 ms |
2252 KB |
Output is correct |
15 |
Correct |
45 ms |
2252 KB |
Output is correct |
16 |
Correct |
48 ms |
2252 KB |
Output is correct |
17 |
Correct |
28 ms |
2232 KB |
Output is correct |
18 |
Correct |
35 ms |
2124 KB |
Output is correct |
19 |
Correct |
38 ms |
2252 KB |
Output is correct |
20 |
Correct |
43 ms |
2256 KB |
Output is correct |
21 |
Correct |
87 ms |
2260 KB |
Output is correct |
22 |
Correct |
102 ms |
2268 KB |
Output is correct |
23 |
Correct |
69 ms |
2252 KB |
Output is correct |
24 |
Correct |
132 ms |
2276 KB |
Output is correct |
25 |
Correct |
134 ms |
2252 KB |
Output is correct |
26 |
Correct |
136 ms |
2308 KB |
Output is correct |
27 |
Correct |
135 ms |
2308 KB |
Output is correct |
28 |
Correct |
131 ms |
2308 KB |
Output is correct |
29 |
Correct |
136 ms |
2252 KB |
Output is correct |
30 |
Correct |
130 ms |
2200 KB |
Output is correct |
31 |
Correct |
135 ms |
2252 KB |
Output is correct |
32 |
Correct |
134 ms |
2280 KB |
Output is correct |
33 |
Correct |
135 ms |
2376 KB |
Output is correct |
34 |
Correct |
137 ms |
2252 KB |
Output is correct |
35 |
Correct |
133 ms |
2252 KB |
Output is correct |
36 |
Correct |
164 ms |
2256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
10 |
Correct |
44 ms |
2340 KB |
Output is correct |
11 |
Correct |
46 ms |
2232 KB |
Output is correct |
12 |
Correct |
47 ms |
2256 KB |
Output is correct |
13 |
Correct |
39 ms |
2252 KB |
Output is correct |
14 |
Correct |
40 ms |
2252 KB |
Output is correct |
15 |
Correct |
45 ms |
2252 KB |
Output is correct |
16 |
Correct |
48 ms |
2252 KB |
Output is correct |
17 |
Correct |
28 ms |
2232 KB |
Output is correct |
18 |
Correct |
35 ms |
2124 KB |
Output is correct |
19 |
Correct |
38 ms |
2252 KB |
Output is correct |
20 |
Correct |
43 ms |
2256 KB |
Output is correct |
21 |
Correct |
87 ms |
2260 KB |
Output is correct |
22 |
Correct |
102 ms |
2268 KB |
Output is correct |
23 |
Correct |
69 ms |
2252 KB |
Output is correct |
24 |
Correct |
132 ms |
2276 KB |
Output is correct |
25 |
Correct |
134 ms |
2252 KB |
Output is correct |
26 |
Correct |
136 ms |
2308 KB |
Output is correct |
27 |
Correct |
135 ms |
2308 KB |
Output is correct |
28 |
Correct |
131 ms |
2308 KB |
Output is correct |
29 |
Correct |
136 ms |
2252 KB |
Output is correct |
30 |
Correct |
130 ms |
2200 KB |
Output is correct |
31 |
Correct |
135 ms |
2252 KB |
Output is correct |
32 |
Correct |
134 ms |
2280 KB |
Output is correct |
33 |
Correct |
135 ms |
2376 KB |
Output is correct |
34 |
Correct |
137 ms |
2252 KB |
Output is correct |
35 |
Correct |
133 ms |
2252 KB |
Output is correct |
36 |
Correct |
164 ms |
2256 KB |
Output is correct |
37 |
Correct |
270 ms |
2492 KB |
Output is correct |
38 |
Correct |
258 ms |
2524 KB |
Output is correct |
39 |
Correct |
325 ms |
2636 KB |
Output is correct |
40 |
Correct |
365 ms |
2620 KB |
Output is correct |
41 |
Correct |
362 ms |
2780 KB |
Output is correct |
42 |
Correct |
328 ms |
2636 KB |
Output is correct |
43 |
Correct |
322 ms |
3056 KB |
Output is correct |
44 |
Correct |
341 ms |
3064 KB |
Output is correct |
45 |
Correct |
342 ms |
3064 KB |
Output is correct |
46 |
Correct |
360 ms |
2504 KB |
Output is correct |
47 |
Correct |
333 ms |
2636 KB |
Output is correct |
48 |
Correct |
332 ms |
3012 KB |
Output is correct |
49 |
Correct |
329 ms |
2716 KB |
Output is correct |
50 |
Correct |
334 ms |
2620 KB |
Output is correct |
51 |
Correct |
93 ms |
2244 KB |
Output is correct |
52 |
Correct |
355 ms |
3172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
10 |
Correct |
44 ms |
2340 KB |
Output is correct |
11 |
Correct |
46 ms |
2232 KB |
Output is correct |
12 |
Correct |
47 ms |
2256 KB |
Output is correct |
13 |
Correct |
39 ms |
2252 KB |
Output is correct |
14 |
Correct |
40 ms |
2252 KB |
Output is correct |
15 |
Correct |
45 ms |
2252 KB |
Output is correct |
16 |
Correct |
48 ms |
2252 KB |
Output is correct |
17 |
Correct |
28 ms |
2232 KB |
Output is correct |
18 |
Correct |
35 ms |
2124 KB |
Output is correct |
19 |
Correct |
38 ms |
2252 KB |
Output is correct |
20 |
Correct |
43 ms |
2256 KB |
Output is correct |
21 |
Correct |
87 ms |
2260 KB |
Output is correct |
22 |
Correct |
102 ms |
2268 KB |
Output is correct |
23 |
Correct |
69 ms |
2252 KB |
Output is correct |
24 |
Correct |
132 ms |
2276 KB |
Output is correct |
25 |
Correct |
134 ms |
2252 KB |
Output is correct |
26 |
Correct |
136 ms |
2308 KB |
Output is correct |
27 |
Correct |
135 ms |
2308 KB |
Output is correct |
28 |
Correct |
131 ms |
2308 KB |
Output is correct |
29 |
Correct |
136 ms |
2252 KB |
Output is correct |
30 |
Correct |
130 ms |
2200 KB |
Output is correct |
31 |
Correct |
135 ms |
2252 KB |
Output is correct |
32 |
Correct |
134 ms |
2280 KB |
Output is correct |
33 |
Correct |
135 ms |
2376 KB |
Output is correct |
34 |
Correct |
137 ms |
2252 KB |
Output is correct |
35 |
Correct |
133 ms |
2252 KB |
Output is correct |
36 |
Correct |
164 ms |
2256 KB |
Output is correct |
37 |
Correct |
270 ms |
2492 KB |
Output is correct |
38 |
Correct |
258 ms |
2524 KB |
Output is correct |
39 |
Correct |
325 ms |
2636 KB |
Output is correct |
40 |
Correct |
365 ms |
2620 KB |
Output is correct |
41 |
Correct |
362 ms |
2780 KB |
Output is correct |
42 |
Correct |
328 ms |
2636 KB |
Output is correct |
43 |
Correct |
322 ms |
3056 KB |
Output is correct |
44 |
Correct |
341 ms |
3064 KB |
Output is correct |
45 |
Correct |
342 ms |
3064 KB |
Output is correct |
46 |
Correct |
360 ms |
2504 KB |
Output is correct |
47 |
Correct |
333 ms |
2636 KB |
Output is correct |
48 |
Correct |
332 ms |
3012 KB |
Output is correct |
49 |
Correct |
329 ms |
2716 KB |
Output is correct |
50 |
Correct |
334 ms |
2620 KB |
Output is correct |
51 |
Correct |
93 ms |
2244 KB |
Output is correct |
52 |
Correct |
355 ms |
3172 KB |
Output is correct |
53 |
Correct |
436 ms |
2848 KB |
Output is correct |
54 |
Correct |
465 ms |
3140 KB |
Output is correct |
55 |
Correct |
471 ms |
3644 KB |
Output is correct |
56 |
Correct |
407 ms |
3152 KB |
Output is correct |
57 |
Correct |
459 ms |
3872 KB |
Output is correct |
58 |
Correct |
465 ms |
3140 KB |
Output is correct |
59 |
Correct |
477 ms |
3344 KB |
Output is correct |
60 |
Correct |
140 ms |
2252 KB |
Output is correct |
61 |
Correct |
461 ms |
3416 KB |
Output is correct |
62 |
Correct |
445 ms |
3496 KB |
Output is correct |
63 |
Correct |
434 ms |
3556 KB |
Output is correct |
64 |
Correct |
415 ms |
3644 KB |
Output is correct |
65 |
Correct |
421 ms |
2616 KB |
Output is correct |
66 |
Correct |
441 ms |
2656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2252 KB |
Output is correct |
2 |
Correct |
10 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
8 ms |
2256 KB |
Output is correct |
5 |
Correct |
18 ms |
2252 KB |
Output is correct |
6 |
Correct |
17 ms |
2264 KB |
Output is correct |
7 |
Correct |
10 ms |
2252 KB |
Output is correct |
8 |
Correct |
18 ms |
2264 KB |
Output is correct |
9 |
Correct |
15 ms |
2256 KB |
Output is correct |
10 |
Correct |
44 ms |
2340 KB |
Output is correct |
11 |
Correct |
46 ms |
2232 KB |
Output is correct |
12 |
Correct |
47 ms |
2256 KB |
Output is correct |
13 |
Correct |
39 ms |
2252 KB |
Output is correct |
14 |
Correct |
40 ms |
2252 KB |
Output is correct |
15 |
Correct |
45 ms |
2252 KB |
Output is correct |
16 |
Correct |
48 ms |
2252 KB |
Output is correct |
17 |
Correct |
28 ms |
2232 KB |
Output is correct |
18 |
Correct |
35 ms |
2124 KB |
Output is correct |
19 |
Correct |
38 ms |
2252 KB |
Output is correct |
20 |
Correct |
43 ms |
2256 KB |
Output is correct |
21 |
Correct |
87 ms |
2260 KB |
Output is correct |
22 |
Correct |
102 ms |
2268 KB |
Output is correct |
23 |
Correct |
69 ms |
2252 KB |
Output is correct |
24 |
Correct |
132 ms |
2276 KB |
Output is correct |
25 |
Correct |
134 ms |
2252 KB |
Output is correct |
26 |
Correct |
136 ms |
2308 KB |
Output is correct |
27 |
Correct |
135 ms |
2308 KB |
Output is correct |
28 |
Correct |
131 ms |
2308 KB |
Output is correct |
29 |
Correct |
136 ms |
2252 KB |
Output is correct |
30 |
Correct |
130 ms |
2200 KB |
Output is correct |
31 |
Correct |
135 ms |
2252 KB |
Output is correct |
32 |
Correct |
134 ms |
2280 KB |
Output is correct |
33 |
Correct |
135 ms |
2376 KB |
Output is correct |
34 |
Correct |
137 ms |
2252 KB |
Output is correct |
35 |
Correct |
133 ms |
2252 KB |
Output is correct |
36 |
Correct |
164 ms |
2256 KB |
Output is correct |
37 |
Correct |
270 ms |
2492 KB |
Output is correct |
38 |
Correct |
258 ms |
2524 KB |
Output is correct |
39 |
Correct |
325 ms |
2636 KB |
Output is correct |
40 |
Correct |
365 ms |
2620 KB |
Output is correct |
41 |
Correct |
362 ms |
2780 KB |
Output is correct |
42 |
Correct |
328 ms |
2636 KB |
Output is correct |
43 |
Correct |
322 ms |
3056 KB |
Output is correct |
44 |
Correct |
341 ms |
3064 KB |
Output is correct |
45 |
Correct |
342 ms |
3064 KB |
Output is correct |
46 |
Correct |
360 ms |
2504 KB |
Output is correct |
47 |
Correct |
333 ms |
2636 KB |
Output is correct |
48 |
Correct |
332 ms |
3012 KB |
Output is correct |
49 |
Correct |
329 ms |
2716 KB |
Output is correct |
50 |
Correct |
334 ms |
2620 KB |
Output is correct |
51 |
Correct |
93 ms |
2244 KB |
Output is correct |
52 |
Correct |
355 ms |
3172 KB |
Output is correct |
53 |
Correct |
436 ms |
2848 KB |
Output is correct |
54 |
Correct |
465 ms |
3140 KB |
Output is correct |
55 |
Correct |
471 ms |
3644 KB |
Output is correct |
56 |
Correct |
407 ms |
3152 KB |
Output is correct |
57 |
Correct |
459 ms |
3872 KB |
Output is correct |
58 |
Correct |
465 ms |
3140 KB |
Output is correct |
59 |
Correct |
477 ms |
3344 KB |
Output is correct |
60 |
Correct |
140 ms |
2252 KB |
Output is correct |
61 |
Correct |
461 ms |
3416 KB |
Output is correct |
62 |
Correct |
445 ms |
3496 KB |
Output is correct |
63 |
Correct |
434 ms |
3556 KB |
Output is correct |
64 |
Correct |
415 ms |
3644 KB |
Output is correct |
65 |
Correct |
421 ms |
2616 KB |
Output is correct |
66 |
Correct |
441 ms |
2656 KB |
Output is correct |
67 |
Correct |
542 ms |
3376 KB |
Output is correct |
68 |
Correct |
192 ms |
2252 KB |
Output is correct |
69 |
Correct |
663 ms |
5048 KB |
Output is correct |
70 |
Correct |
665 ms |
4004 KB |
Output is correct |
71 |
Correct |
661 ms |
3844 KB |
Output is correct |
72 |
Correct |
667 ms |
3272 KB |
Output is correct |
73 |
Correct |
648 ms |
3284 KB |
Output is correct |
74 |
Correct |
664 ms |
5140 KB |
Output is correct |
75 |
Correct |
656 ms |
4624 KB |
Output is correct |
76 |
Correct |
705 ms |
5304 KB |
Output is correct |
77 |
Correct |
674 ms |
5356 KB |
Output is correct |