Submission #856374

# Submission time Handle Problem Language Result Execution time Memory
856374 2023-10-03T09:18:34 Z hgglmao Bootfall (IZhO17_bootfall) C++17
100 / 100
288 ms 3156 KB
#include <bits/stdc++.h>
#define TASK "bootfall"

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ll> ill;
typedef pair<ll, int> lli;
typedef pair<ll, ll> pll;

const int MAX = 501;
const int SQMAX = 250001;

int n, a[MAX];
int sum;
ll dp[SQMAX];
bool check[SQMAX];

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

        if (fopen(TASK ".inp", "r"))
        {
                freopen(TASK ".inp", "r", stdin);
                freopen(TASK ".out", "w", stdout);
        }

        cin >> n;
        for (int i = 1; i <= n; ++i)
                cin >> a[i];

        sum = accumulate(a + 1, a + n + 1, 0);
        dp[0] = 1;
        for (int i = 1; i <= n; ++i)
                for (int j = sum - a[i]; j >= 0; --j)
                        dp[j + a[i]] += dp[j];

        if (sum % 2 || !dp[sum / 2])
                return cout << 0, 0;

        fill(check + 1, check + sum + 1, 1);
        for (int i = 1; i <= n; ++i)
        {
                for (int j = 0; j <= sum - a[i]; ++j)
                        dp[j + a[i]] -= dp[j];
                for (int cur = 1; cur <= sum; ++cur)
                {
                        if ((sum - a[i] + cur) % 2)
                        {
                                check[cur] = 0;
                                continue;
                        }
                        int cur_req = (sum - a[i] + cur) / 2;
                        if (cur_req <= sum && dp[cur_req])
                                continue;
                        // if (cur_req - cur >= 0 && cur_req - cur <= sum && dp[cur_req - cur])
                        //         continue;
                        check[cur] = 0;
                }
                for (int j = sum - a[i]; j >= 0; --j)
                        dp[j + a[i]] += dp[j];
        }

        cout << accumulate(check, check + sum + 1, 0) << '\n';
        for (int i = 0; i <= sum; ++i)
                if (check[i])
                        cout << i << ' ';
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:28:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |                 freopen(TASK ".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:29:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |                 freopen(TASK ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 496 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 444 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 496 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 444 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 10 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 37 ms 860 KB Output is correct
40 Correct 24 ms 800 KB Output is correct
41 Correct 46 ms 1040 KB Output is correct
42 Correct 18 ms 600 KB Output is correct
43 Correct 32 ms 944 KB Output is correct
44 Correct 38 ms 948 KB Output is correct
45 Correct 35 ms 960 KB Output is correct
46 Correct 20 ms 600 KB Output is correct
47 Correct 20 ms 604 KB Output is correct
48 Correct 37 ms 860 KB Output is correct
49 Correct 37 ms 1000 KB Output is correct
50 Correct 20 ms 604 KB Output is correct
51 Correct 4 ms 604 KB Output is correct
52 Correct 44 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 496 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 444 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 10 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 37 ms 860 KB Output is correct
40 Correct 24 ms 800 KB Output is correct
41 Correct 46 ms 1040 KB Output is correct
42 Correct 18 ms 600 KB Output is correct
43 Correct 32 ms 944 KB Output is correct
44 Correct 38 ms 948 KB Output is correct
45 Correct 35 ms 960 KB Output is correct
46 Correct 20 ms 600 KB Output is correct
47 Correct 20 ms 604 KB Output is correct
48 Correct 37 ms 860 KB Output is correct
49 Correct 37 ms 1000 KB Output is correct
50 Correct 20 ms 604 KB Output is correct
51 Correct 4 ms 604 KB Output is correct
52 Correct 44 ms 1068 KB Output is correct
53 Correct 32 ms 860 KB Output is correct
54 Correct 46 ms 904 KB Output is correct
55 Correct 95 ms 1684 KB Output is correct
56 Correct 40 ms 936 KB Output is correct
57 Correct 96 ms 1724 KB Output is correct
58 Correct 50 ms 1112 KB Output is correct
59 Correct 62 ms 1112 KB Output is correct
60 Correct 10 ms 856 KB Output is correct
61 Correct 73 ms 1200 KB Output is correct
62 Correct 71 ms 1360 KB Output is correct
63 Correct 77 ms 1612 KB Output is correct
64 Correct 80 ms 1760 KB Output is correct
65 Correct 39 ms 860 KB Output is correct
66 Correct 54 ms 936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 496 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 3 ms 348 KB Output is correct
35 Correct 3 ms 444 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 10 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 37 ms 860 KB Output is correct
40 Correct 24 ms 800 KB Output is correct
41 Correct 46 ms 1040 KB Output is correct
42 Correct 18 ms 600 KB Output is correct
43 Correct 32 ms 944 KB Output is correct
44 Correct 38 ms 948 KB Output is correct
45 Correct 35 ms 960 KB Output is correct
46 Correct 20 ms 600 KB Output is correct
47 Correct 20 ms 604 KB Output is correct
48 Correct 37 ms 860 KB Output is correct
49 Correct 37 ms 1000 KB Output is correct
50 Correct 20 ms 604 KB Output is correct
51 Correct 4 ms 604 KB Output is correct
52 Correct 44 ms 1068 KB Output is correct
53 Correct 32 ms 860 KB Output is correct
54 Correct 46 ms 904 KB Output is correct
55 Correct 95 ms 1684 KB Output is correct
56 Correct 40 ms 936 KB Output is correct
57 Correct 96 ms 1724 KB Output is correct
58 Correct 50 ms 1112 KB Output is correct
59 Correct 62 ms 1112 KB Output is correct
60 Correct 10 ms 856 KB Output is correct
61 Correct 73 ms 1200 KB Output is correct
62 Correct 71 ms 1360 KB Output is correct
63 Correct 77 ms 1612 KB Output is correct
64 Correct 80 ms 1760 KB Output is correct
65 Correct 39 ms 860 KB Output is correct
66 Correct 54 ms 936 KB Output is correct
67 Correct 74 ms 1360 KB Output is correct
68 Correct 29 ms 1212 KB Output is correct
69 Correct 256 ms 2876 KB Output is correct
70 Correct 149 ms 1832 KB Output is correct
71 Correct 150 ms 1796 KB Output is correct
72 Correct 155 ms 1616 KB Output is correct
73 Correct 143 ms 1368 KB Output is correct
74 Correct 264 ms 2932 KB Output is correct
75 Correct 203 ms 2488 KB Output is correct
76 Correct 285 ms 3140 KB Output is correct
77 Correct 288 ms 3156 KB Output is correct