Submission #706867

# Submission time Handle Problem Language Result Execution time Memory
706867 2023-03-07T23:33:07 Z Shreyan_Paliwal Bootfall (IZhO17_bootfall) C++17
100 / 100
350 ms 3916 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 500;
const int maxk = maxn * maxn;

int n;
int dp[maxk + 1];
int dp2[maxk + 1];
int weights[maxn];

int main() {
    // freopen("main.in", "r", stdin);

    cin >> n;
    for (int i = 0; i < n; i++) cin >> weights[i];

    // calc knapsack
    dp[0] = 1;
    for (int i = 0; i < n; i++) { // for weight
        for (int j = maxk; j >= weights[i]; j--) {
            dp[j] += dp[j - weights[i]];
        }
    }

    int sm = accumulate(weights, weights + n, 0);
    if (sm & 1 || !dp[sm / 2]) {
        cout << 0 << endl;
        return 0;
    }

    int works[maxk + 1];
    fill(works, works + maxk + 1, 1);
    // for each weight
    for (int i = 0; i < n; i++) {
        // remove weight
        for (int j = 0; j <= maxk; j++) dp2[j] = dp[j];
        for (int j = weights[i]; j <= maxk; j++) dp2[j] -= dp2[j - weights[i]];


        // update works array
        for (int j = 1; j <= maxk; j++) {
            int SM = sm - weights[i] + j;
            if (SM & 1 || !dp2[SM / 2])
                works[j] = false;
        }
    }

    int ans = accumulate(works + 1, works + maxk + 1, 0);
    cout << ans << endl;
    for (int i = 1; i <= maxk; i++)
        if (works[i]) cout << i << ' ';
    cout << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 20 ms 3156 KB Output is correct
11 Correct 21 ms 3204 KB Output is correct
12 Correct 20 ms 3156 KB Output is correct
13 Correct 17 ms 3232 KB Output is correct
14 Correct 25 ms 3236 KB Output is correct
15 Correct 20 ms 3156 KB Output is correct
16 Correct 22 ms 3156 KB Output is correct
17 Correct 13 ms 3236 KB Output is correct
18 Correct 17 ms 3236 KB Output is correct
19 Correct 18 ms 3156 KB Output is correct
20 Correct 21 ms 3224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 20 ms 3156 KB Output is correct
11 Correct 21 ms 3204 KB Output is correct
12 Correct 20 ms 3156 KB Output is correct
13 Correct 17 ms 3232 KB Output is correct
14 Correct 25 ms 3236 KB Output is correct
15 Correct 20 ms 3156 KB Output is correct
16 Correct 22 ms 3156 KB Output is correct
17 Correct 13 ms 3236 KB Output is correct
18 Correct 17 ms 3236 KB Output is correct
19 Correct 18 ms 3156 KB Output is correct
20 Correct 21 ms 3224 KB Output is correct
21 Correct 51 ms 3196 KB Output is correct
22 Correct 62 ms 3216 KB Output is correct
23 Correct 36 ms 3224 KB Output is correct
24 Correct 57 ms 3220 KB Output is correct
25 Correct 55 ms 3216 KB Output is correct
26 Correct 58 ms 3156 KB Output is correct
27 Correct 71 ms 3212 KB Output is correct
28 Correct 58 ms 3216 KB Output is correct
29 Correct 60 ms 3212 KB Output is correct
30 Correct 57 ms 3156 KB Output is correct
31 Correct 59 ms 3220 KB Output is correct
32 Correct 65 ms 3248 KB Output is correct
33 Correct 58 ms 3220 KB Output is correct
34 Correct 57 ms 3156 KB Output is correct
35 Correct 57 ms 3156 KB Output is correct
36 Correct 58 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 20 ms 3156 KB Output is correct
11 Correct 21 ms 3204 KB Output is correct
12 Correct 20 ms 3156 KB Output is correct
13 Correct 17 ms 3232 KB Output is correct
14 Correct 25 ms 3236 KB Output is correct
15 Correct 20 ms 3156 KB Output is correct
16 Correct 22 ms 3156 KB Output is correct
17 Correct 13 ms 3236 KB Output is correct
18 Correct 17 ms 3236 KB Output is correct
19 Correct 18 ms 3156 KB Output is correct
20 Correct 21 ms 3224 KB Output is correct
21 Correct 51 ms 3196 KB Output is correct
22 Correct 62 ms 3216 KB Output is correct
23 Correct 36 ms 3224 KB Output is correct
24 Correct 57 ms 3220 KB Output is correct
25 Correct 55 ms 3216 KB Output is correct
26 Correct 58 ms 3156 KB Output is correct
27 Correct 71 ms 3212 KB Output is correct
28 Correct 58 ms 3216 KB Output is correct
29 Correct 60 ms 3212 KB Output is correct
30 Correct 57 ms 3156 KB Output is correct
31 Correct 59 ms 3220 KB Output is correct
32 Correct 65 ms 3248 KB Output is correct
33 Correct 58 ms 3220 KB Output is correct
34 Correct 57 ms 3156 KB Output is correct
35 Correct 57 ms 3156 KB Output is correct
36 Correct 58 ms 3216 KB Output is correct
37 Correct 114 ms 3208 KB Output is correct
38 Correct 112 ms 3196 KB Output is correct
39 Correct 137 ms 3216 KB Output is correct
40 Correct 166 ms 3220 KB Output is correct
41 Correct 149 ms 3216 KB Output is correct
42 Correct 144 ms 3216 KB Output is correct
43 Correct 182 ms 3344 KB Output is correct
44 Correct 143 ms 3264 KB Output is correct
45 Correct 142 ms 3344 KB Output is correct
46 Correct 150 ms 3148 KB Output is correct
47 Correct 144 ms 3272 KB Output is correct
48 Correct 146 ms 3272 KB Output is correct
49 Correct 195 ms 3276 KB Output is correct
50 Correct 141 ms 3216 KB Output is correct
51 Correct 30 ms 2132 KB Output is correct
52 Correct 156 ms 3344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 20 ms 3156 KB Output is correct
11 Correct 21 ms 3204 KB Output is correct
12 Correct 20 ms 3156 KB Output is correct
13 Correct 17 ms 3232 KB Output is correct
14 Correct 25 ms 3236 KB Output is correct
15 Correct 20 ms 3156 KB Output is correct
16 Correct 22 ms 3156 KB Output is correct
17 Correct 13 ms 3236 KB Output is correct
18 Correct 17 ms 3236 KB Output is correct
19 Correct 18 ms 3156 KB Output is correct
20 Correct 21 ms 3224 KB Output is correct
21 Correct 51 ms 3196 KB Output is correct
22 Correct 62 ms 3216 KB Output is correct
23 Correct 36 ms 3224 KB Output is correct
24 Correct 57 ms 3220 KB Output is correct
25 Correct 55 ms 3216 KB Output is correct
26 Correct 58 ms 3156 KB Output is correct
27 Correct 71 ms 3212 KB Output is correct
28 Correct 58 ms 3216 KB Output is correct
29 Correct 60 ms 3212 KB Output is correct
30 Correct 57 ms 3156 KB Output is correct
31 Correct 59 ms 3220 KB Output is correct
32 Correct 65 ms 3248 KB Output is correct
33 Correct 58 ms 3220 KB Output is correct
34 Correct 57 ms 3156 KB Output is correct
35 Correct 57 ms 3156 KB Output is correct
36 Correct 58 ms 3216 KB Output is correct
37 Correct 114 ms 3208 KB Output is correct
38 Correct 112 ms 3196 KB Output is correct
39 Correct 137 ms 3216 KB Output is correct
40 Correct 166 ms 3220 KB Output is correct
41 Correct 149 ms 3216 KB Output is correct
42 Correct 144 ms 3216 KB Output is correct
43 Correct 182 ms 3344 KB Output is correct
44 Correct 143 ms 3264 KB Output is correct
45 Correct 142 ms 3344 KB Output is correct
46 Correct 150 ms 3148 KB Output is correct
47 Correct 144 ms 3272 KB Output is correct
48 Correct 146 ms 3272 KB Output is correct
49 Correct 195 ms 3276 KB Output is correct
50 Correct 141 ms 3216 KB Output is correct
51 Correct 30 ms 2132 KB Output is correct
52 Correct 156 ms 3344 KB Output is correct
53 Correct 199 ms 3392 KB Output is correct
54 Correct 198 ms 3436 KB Output is correct
55 Correct 209 ms 3468 KB Output is correct
56 Correct 184 ms 3340 KB Output is correct
57 Correct 207 ms 3516 KB Output is correct
58 Correct 206 ms 3340 KB Output is correct
59 Correct 223 ms 3348 KB Output is correct
60 Correct 44 ms 2132 KB Output is correct
61 Correct 221 ms 3348 KB Output is correct
62 Correct 187 ms 3400 KB Output is correct
63 Correct 205 ms 3464 KB Output is correct
64 Correct 188 ms 3600 KB Output is correct
65 Correct 179 ms 3216 KB Output is correct
66 Correct 185 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3152 KB Output is correct
2 Correct 8 ms 3236 KB Output is correct
3 Correct 2 ms 2260 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 9 ms 3156 KB Output is correct
6 Correct 7 ms 3232 KB Output is correct
7 Correct 6 ms 3228 KB Output is correct
8 Correct 10 ms 3236 KB Output is correct
9 Correct 8 ms 3156 KB Output is correct
10 Correct 20 ms 3156 KB Output is correct
11 Correct 21 ms 3204 KB Output is correct
12 Correct 20 ms 3156 KB Output is correct
13 Correct 17 ms 3232 KB Output is correct
14 Correct 25 ms 3236 KB Output is correct
15 Correct 20 ms 3156 KB Output is correct
16 Correct 22 ms 3156 KB Output is correct
17 Correct 13 ms 3236 KB Output is correct
18 Correct 17 ms 3236 KB Output is correct
19 Correct 18 ms 3156 KB Output is correct
20 Correct 21 ms 3224 KB Output is correct
21 Correct 51 ms 3196 KB Output is correct
22 Correct 62 ms 3216 KB Output is correct
23 Correct 36 ms 3224 KB Output is correct
24 Correct 57 ms 3220 KB Output is correct
25 Correct 55 ms 3216 KB Output is correct
26 Correct 58 ms 3156 KB Output is correct
27 Correct 71 ms 3212 KB Output is correct
28 Correct 58 ms 3216 KB Output is correct
29 Correct 60 ms 3212 KB Output is correct
30 Correct 57 ms 3156 KB Output is correct
31 Correct 59 ms 3220 KB Output is correct
32 Correct 65 ms 3248 KB Output is correct
33 Correct 58 ms 3220 KB Output is correct
34 Correct 57 ms 3156 KB Output is correct
35 Correct 57 ms 3156 KB Output is correct
36 Correct 58 ms 3216 KB Output is correct
37 Correct 114 ms 3208 KB Output is correct
38 Correct 112 ms 3196 KB Output is correct
39 Correct 137 ms 3216 KB Output is correct
40 Correct 166 ms 3220 KB Output is correct
41 Correct 149 ms 3216 KB Output is correct
42 Correct 144 ms 3216 KB Output is correct
43 Correct 182 ms 3344 KB Output is correct
44 Correct 143 ms 3264 KB Output is correct
45 Correct 142 ms 3344 KB Output is correct
46 Correct 150 ms 3148 KB Output is correct
47 Correct 144 ms 3272 KB Output is correct
48 Correct 146 ms 3272 KB Output is correct
49 Correct 195 ms 3276 KB Output is correct
50 Correct 141 ms 3216 KB Output is correct
51 Correct 30 ms 2132 KB Output is correct
52 Correct 156 ms 3344 KB Output is correct
53 Correct 199 ms 3392 KB Output is correct
54 Correct 198 ms 3436 KB Output is correct
55 Correct 209 ms 3468 KB Output is correct
56 Correct 184 ms 3340 KB Output is correct
57 Correct 207 ms 3516 KB Output is correct
58 Correct 206 ms 3340 KB Output is correct
59 Correct 223 ms 3348 KB Output is correct
60 Correct 44 ms 2132 KB Output is correct
61 Correct 221 ms 3348 KB Output is correct
62 Correct 187 ms 3400 KB Output is correct
63 Correct 205 ms 3464 KB Output is correct
64 Correct 188 ms 3600 KB Output is correct
65 Correct 179 ms 3216 KB Output is correct
66 Correct 185 ms 3216 KB Output is correct
67 Correct 233 ms 3340 KB Output is correct
68 Correct 60 ms 2236 KB Output is correct
69 Correct 350 ms 3864 KB Output is correct
70 Correct 294 ms 3596 KB Output is correct
71 Correct 309 ms 3600 KB Output is correct
72 Correct 318 ms 3268 KB Output is correct
73 Correct 284 ms 3148 KB Output is correct
74 Correct 314 ms 3912 KB Output is correct
75 Correct 304 ms 3728 KB Output is correct
76 Correct 313 ms 3916 KB Output is correct
77 Correct 308 ms 3852 KB Output is correct