Submission #405192

# Submission time Handle Problem Language Result Execution time Memory
405192 2021-05-15T20:41:57 Z Falcon Bootfall (IZhO17_bootfall) C++17
100 / 100
746 ms 3908 KB
#include <bits/stdc++.h>

#ifdef DEBUG
#include "debug.hpp"
#endif

using namespace std;

#define all(c)              (c).begin(), (c).end()
#define rall(c)             (c).rbegin(), (c).rend()
#define traverse(c, it)     for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N)           for(int i = 0; i < (N); ++i)
#define rrep(i, N)          for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N)          for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e)       for(int i = (s); i <= (e); ++i)

#ifdef DEBUG
#define debug(x...)         { \
                            ++dbg::depth; \
                            string dbg_vals = dbg::to_string(x); \
                            --dbg::depth; \
                            dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
                            }

#define light_debug(x)      { \
                            dbg::light = true; \
                            dbg::dout << __func__ << ":" << __LINE__; \
                            dbg::dout << "  " << #x << " = " << x << endl; \
                            dbg::light = false; \
                            }

#else
#define debug(x...)         42
#define light_debug(x)      42
#endif


using ll = long long;

template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }

template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }


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

    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    int s{accumulate(all(a), 0)};

    vector<long long> ways(s + 1);
    ways[0] = 1; 

    auto add = [&](int x) {
        rrep(i, int(ways.size()))
            if(i - x >= 0) ways[i] += ways[i - x];
    };

    auto remove = [&](int x) {
        rep(i, int(ways.size()))
            if(i - x >= 0) ways[i] -= ways[i - x];
    };

    rep(i, n) add(a[i]);
    debug(ways);

    if(s % 2 != 0 || ways[s / 2] == 0)
        return cout << 0 << '\n', 0;

    vector<int> c(s + 1);
    vector<bool> b(s + 1);
    rep(i, n) {
        remove(a[i]);
        rep(x, int(ways.size())) {
            if(ways[x] == 0) continue;
            b[abs(s - a[i] - 2 * x)] = true;
        }

        rep(x, int(c.size()))
            if(b[x]) ++c[x], b[x] = false; 
        debug(i, ways);
        add(a[i]);
    }

    cout <<  count_if(all(c), [&](int x) { return x == n; }) << '\n';

    rep(i, int(c.size())) if(c[i] == n) cout << i << ' ';
    cout << '\n';
    
    
    #ifdef DEBUG
    dbg::dout << "\nExecution time: "
              << clock() * 1000 / CLOCKS_PER_SEC 
              << "ms" << endl;
    #endif
    return 0;
}


Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
bootfall.cpp:69:5: note: in expansion of macro 'debug'
   69 |     debug(ways);
      |     ^~~~~
bootfall.cpp:33:29: warning: statement has no effect [-Wunused-value]
   33 | #define debug(x...)         42
      |                             ^~
bootfall.cpp:85:9: note: in expansion of macro 'debug'
   85 |         debug(i, ways);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 6 ms 440 KB Output is correct
26 Correct 7 ms 436 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 392 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 332 KB Output is correct
32 Correct 4 ms 312 KB Output is correct
33 Correct 5 ms 428 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 6 ms 440 KB Output is correct
26 Correct 7 ms 436 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 392 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 332 KB Output is correct
32 Correct 4 ms 312 KB Output is correct
33 Correct 5 ms 428 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
37 Correct 27 ms 552 KB Output is correct
38 Correct 30 ms 548 KB Output is correct
39 Correct 79 ms 1040 KB Output is correct
40 Correct 55 ms 708 KB Output is correct
41 Correct 85 ms 1100 KB Output is correct
42 Correct 48 ms 660 KB Output is correct
43 Correct 82 ms 1096 KB Output is correct
44 Correct 89 ms 1140 KB Output is correct
45 Correct 89 ms 1092 KB Output is correct
46 Correct 40 ms 588 KB Output is correct
47 Correct 53 ms 704 KB Output is correct
48 Correct 96 ms 1036 KB Output is correct
49 Correct 83 ms 1056 KB Output is correct
50 Correct 51 ms 688 KB Output is correct
51 Correct 8 ms 460 KB Output is correct
52 Correct 111 ms 1268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 6 ms 440 KB Output is correct
26 Correct 7 ms 436 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 392 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 332 KB Output is correct
32 Correct 4 ms 312 KB Output is correct
33 Correct 5 ms 428 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
37 Correct 27 ms 552 KB Output is correct
38 Correct 30 ms 548 KB Output is correct
39 Correct 79 ms 1040 KB Output is correct
40 Correct 55 ms 708 KB Output is correct
41 Correct 85 ms 1100 KB Output is correct
42 Correct 48 ms 660 KB Output is correct
43 Correct 82 ms 1096 KB Output is correct
44 Correct 89 ms 1140 KB Output is correct
45 Correct 89 ms 1092 KB Output is correct
46 Correct 40 ms 588 KB Output is correct
47 Correct 53 ms 704 KB Output is correct
48 Correct 96 ms 1036 KB Output is correct
49 Correct 83 ms 1056 KB Output is correct
50 Correct 51 ms 688 KB Output is correct
51 Correct 8 ms 460 KB Output is correct
52 Correct 111 ms 1268 KB Output is correct
53 Correct 84 ms 964 KB Output is correct
54 Correct 117 ms 1092 KB Output is correct
55 Correct 248 ms 1880 KB Output is correct
56 Correct 120 ms 1100 KB Output is correct
57 Correct 244 ms 1956 KB Output is correct
58 Correct 140 ms 1160 KB Output is correct
59 Correct 173 ms 1340 KB Output is correct
60 Correct 16 ms 716 KB Output is correct
61 Correct 198 ms 1452 KB Output is correct
62 Correct 195 ms 1704 KB Output is correct
63 Correct 218 ms 1732 KB Output is correct
64 Correct 195 ms 1896 KB Output is correct
65 Correct 76 ms 964 KB Output is correct
66 Correct 77 ms 940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 6 ms 440 KB Output is correct
26 Correct 7 ms 436 KB Output is correct
27 Correct 5 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 392 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 332 KB Output is correct
32 Correct 4 ms 312 KB Output is correct
33 Correct 5 ms 428 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 332 KB Output is correct
36 Correct 4 ms 332 KB Output is correct
37 Correct 27 ms 552 KB Output is correct
38 Correct 30 ms 548 KB Output is correct
39 Correct 79 ms 1040 KB Output is correct
40 Correct 55 ms 708 KB Output is correct
41 Correct 85 ms 1100 KB Output is correct
42 Correct 48 ms 660 KB Output is correct
43 Correct 82 ms 1096 KB Output is correct
44 Correct 89 ms 1140 KB Output is correct
45 Correct 89 ms 1092 KB Output is correct
46 Correct 40 ms 588 KB Output is correct
47 Correct 53 ms 704 KB Output is correct
48 Correct 96 ms 1036 KB Output is correct
49 Correct 83 ms 1056 KB Output is correct
50 Correct 51 ms 688 KB Output is correct
51 Correct 8 ms 460 KB Output is correct
52 Correct 111 ms 1268 KB Output is correct
53 Correct 84 ms 964 KB Output is correct
54 Correct 117 ms 1092 KB Output is correct
55 Correct 248 ms 1880 KB Output is correct
56 Correct 120 ms 1100 KB Output is correct
57 Correct 244 ms 1956 KB Output is correct
58 Correct 140 ms 1160 KB Output is correct
59 Correct 173 ms 1340 KB Output is correct
60 Correct 16 ms 716 KB Output is correct
61 Correct 198 ms 1452 KB Output is correct
62 Correct 195 ms 1704 KB Output is correct
63 Correct 218 ms 1732 KB Output is correct
64 Correct 195 ms 1896 KB Output is correct
65 Correct 76 ms 964 KB Output is correct
66 Correct 77 ms 940 KB Output is correct
67 Correct 196 ms 1456 KB Output is correct
68 Correct 46 ms 1212 KB Output is correct
69 Correct 628 ms 3372 KB Output is correct
70 Correct 389 ms 2216 KB Output is correct
71 Correct 389 ms 2164 KB Output is correct
72 Correct 371 ms 1800 KB Output is correct
73 Correct 374 ms 1732 KB Output is correct
74 Correct 683 ms 3604 KB Output is correct
75 Correct 526 ms 2892 KB Output is correct
76 Correct 705 ms 3908 KB Output is correct
77 Correct 746 ms 3772 KB Output is correct