Submission #404381

# Submission time Handle Problem Language Result Execution time Memory
404381 2021-05-14T09:58:47 Z fvogel499 Bootfall (IZhO17_bootfall) C++14
100 / 100
641 ms 31704 KB
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

#define pii pair<int, int>
#define f first
#define s second

#define ll long long
#define rint int32_t

const int siz = 250001;

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

    int n;
    cin >> n;

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

    bitset<siz> check(0);
    check[0] = 1;
    int checkSum = 0;
    for (int i = 0; i < n; i++) {
        check |= check<<raw[i];
        checkSum += raw[i];
    }
    if (checkSum%2 == 1 or check[checkSum/2] == 0) {
        cout << 0;
        return 0;
    }

    bitset<siz> startToEnd [n];
    startToEnd[0] = bitset<siz>(0);
    startToEnd[0][0] = 1;
    for (int i = 1; i < n; i++) {
        startToEnd[i] = startToEnd[i-1]|(startToEnd[i-1]<<raw[i-1]);
    }

    bitset<siz> endToStart [n];
    endToStart[n-1] = bitset<siz>(0);
    endToStart[n-1][0] = 1;
    for (int i = n-2; i >= 0; i--) {
        endToStart[i] = endToStart[i+1]|(endToStart[i+1]<<raw[i+1]);
    }

    bitset<siz> even;
    bitset<siz> uneven;
    even.set();
    uneven.set();
    even[0] = 0;
    bool evenKilled = false;
    bool unevenKilled = false;
    bitset<siz> cur;
    int locSum;
    for (int i = 0; i < n; i++) {
        if (i > n/2) {
            cur = startToEnd[i];
            for (int j = i+1; j < n; j++) cur |= cur<<raw[j];
        }
        else {
            cur = endToStart[i];
            for (int j = i-1; j >= 0; j--) cur |= cur<<raw[j];
        }
        locSum = checkSum-raw[i];
        if (locSum%2 == 0) {
            even &= cur>>(locSum/2);
            if (!unevenKilled) {
                uneven &= 0;
                unevenKilled = true;
            }
        }
        else {
            uneven &= cur>>(locSum/2+1);
            if (!evenKilled) {
                even &= 0;
                evenKilled = true;
            }
        }
    }

    cout << even.count()+uneven.count() << endl;
    for (int i = 0; i < siz; i++) {
        if (even[i]) cout << i*2 << " ";
        if (uneven[i]) cout << i*2+1 << " ";
    }

    int d = 0;
    d++;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 7 ms 2252 KB Output is correct
11 Correct 6 ms 2316 KB Output is correct
12 Correct 5 ms 2252 KB Output is correct
13 Correct 4 ms 1996 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 6 ms 2200 KB Output is correct
16 Correct 5 ms 2324 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 6 ms 1896 KB Output is correct
19 Correct 5 ms 1996 KB Output is correct
20 Correct 7 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 7 ms 2252 KB Output is correct
11 Correct 6 ms 2316 KB Output is correct
12 Correct 5 ms 2252 KB Output is correct
13 Correct 4 ms 1996 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 6 ms 2200 KB Output is correct
16 Correct 5 ms 2324 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 6 ms 1896 KB Output is correct
19 Correct 5 ms 1996 KB Output is correct
20 Correct 7 ms 2252 KB Output is correct
21 Correct 16 ms 4408 KB Output is correct
22 Correct 23 ms 4940 KB Output is correct
23 Correct 14 ms 3544 KB Output is correct
24 Correct 30 ms 6220 KB Output is correct
25 Correct 27 ms 6224 KB Output is correct
26 Correct 41 ms 6596 KB Output is correct
27 Correct 31 ms 6656 KB Output is correct
28 Correct 30 ms 6580 KB Output is correct
29 Correct 31 ms 6604 KB Output is correct
30 Correct 30 ms 6476 KB Output is correct
31 Correct 40 ms 6596 KB Output is correct
32 Correct 30 ms 6596 KB Output is correct
33 Correct 31 ms 6476 KB Output is correct
34 Correct 33 ms 6476 KB Output is correct
35 Correct 32 ms 6604 KB Output is correct
36 Correct 31 ms 6600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 7 ms 2252 KB Output is correct
11 Correct 6 ms 2316 KB Output is correct
12 Correct 5 ms 2252 KB Output is correct
13 Correct 4 ms 1996 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 6 ms 2200 KB Output is correct
16 Correct 5 ms 2324 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 6 ms 1896 KB Output is correct
19 Correct 5 ms 1996 KB Output is correct
20 Correct 7 ms 2252 KB Output is correct
21 Correct 16 ms 4408 KB Output is correct
22 Correct 23 ms 4940 KB Output is correct
23 Correct 14 ms 3544 KB Output is correct
24 Correct 30 ms 6220 KB Output is correct
25 Correct 27 ms 6224 KB Output is correct
26 Correct 41 ms 6596 KB Output is correct
27 Correct 31 ms 6656 KB Output is correct
28 Correct 30 ms 6580 KB Output is correct
29 Correct 31 ms 6604 KB Output is correct
30 Correct 30 ms 6476 KB Output is correct
31 Correct 40 ms 6596 KB Output is correct
32 Correct 30 ms 6596 KB Output is correct
33 Correct 31 ms 6476 KB Output is correct
34 Correct 33 ms 6476 KB Output is correct
35 Correct 32 ms 6604 KB Output is correct
36 Correct 31 ms 6600 KB Output is correct
37 Correct 107 ms 12704 KB Output is correct
38 Correct 104 ms 12700 KB Output is correct
39 Correct 166 ms 15632 KB Output is correct
40 Correct 222 ms 17080 KB Output is correct
41 Correct 194 ms 16984 KB Output is correct
42 Correct 183 ms 15764 KB Output is correct
43 Correct 164 ms 15528 KB Output is correct
44 Correct 158 ms 15748 KB Output is correct
45 Correct 190 ms 15888 KB Output is correct
46 Correct 191 ms 16992 KB Output is correct
47 Correct 161 ms 15760 KB Output is correct
48 Correct 164 ms 15812 KB Output is correct
49 Correct 158 ms 15764 KB Output is correct
50 Correct 191 ms 15760 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 184 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 7 ms 2252 KB Output is correct
11 Correct 6 ms 2316 KB Output is correct
12 Correct 5 ms 2252 KB Output is correct
13 Correct 4 ms 1996 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 6 ms 2200 KB Output is correct
16 Correct 5 ms 2324 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 6 ms 1896 KB Output is correct
19 Correct 5 ms 1996 KB Output is correct
20 Correct 7 ms 2252 KB Output is correct
21 Correct 16 ms 4408 KB Output is correct
22 Correct 23 ms 4940 KB Output is correct
23 Correct 14 ms 3544 KB Output is correct
24 Correct 30 ms 6220 KB Output is correct
25 Correct 27 ms 6224 KB Output is correct
26 Correct 41 ms 6596 KB Output is correct
27 Correct 31 ms 6656 KB Output is correct
28 Correct 30 ms 6580 KB Output is correct
29 Correct 31 ms 6604 KB Output is correct
30 Correct 30 ms 6476 KB Output is correct
31 Correct 40 ms 6596 KB Output is correct
32 Correct 30 ms 6596 KB Output is correct
33 Correct 31 ms 6476 KB Output is correct
34 Correct 33 ms 6476 KB Output is correct
35 Correct 32 ms 6604 KB Output is correct
36 Correct 31 ms 6600 KB Output is correct
37 Correct 107 ms 12704 KB Output is correct
38 Correct 104 ms 12700 KB Output is correct
39 Correct 166 ms 15632 KB Output is correct
40 Correct 222 ms 17080 KB Output is correct
41 Correct 194 ms 16984 KB Output is correct
42 Correct 183 ms 15764 KB Output is correct
43 Correct 164 ms 15528 KB Output is correct
44 Correct 158 ms 15748 KB Output is correct
45 Correct 190 ms 15888 KB Output is correct
46 Correct 191 ms 16992 KB Output is correct
47 Correct 161 ms 15760 KB Output is correct
48 Correct 164 ms 15812 KB Output is correct
49 Correct 158 ms 15764 KB Output is correct
50 Correct 191 ms 15760 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 184 ms 17120 KB Output is correct
53 Correct 245 ms 18944 KB Output is correct
54 Correct 359 ms 22004 KB Output is correct
55 Correct 362 ms 22144 KB Output is correct
56 Correct 226 ms 19316 KB Output is correct
57 Correct 320 ms 22136 KB Output is correct
58 Correct 299 ms 22004 KB Output is correct
59 Correct 301 ms 21992 KB Output is correct
60 Correct 4 ms 460 KB Output is correct
61 Correct 296 ms 22008 KB Output is correct
62 Correct 295 ms 20300 KB Output is correct
63 Correct 259 ms 20292 KB Output is correct
64 Correct 258 ms 19928 KB Output is correct
65 Correct 246 ms 19908 KB Output is correct
66 Correct 230 ms 19436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 844 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 1100 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 7 ms 2252 KB Output is correct
11 Correct 6 ms 2316 KB Output is correct
12 Correct 5 ms 2252 KB Output is correct
13 Correct 4 ms 1996 KB Output is correct
14 Correct 6 ms 2124 KB Output is correct
15 Correct 6 ms 2200 KB Output is correct
16 Correct 5 ms 2324 KB Output is correct
17 Correct 3 ms 1484 KB Output is correct
18 Correct 6 ms 1896 KB Output is correct
19 Correct 5 ms 1996 KB Output is correct
20 Correct 7 ms 2252 KB Output is correct
21 Correct 16 ms 4408 KB Output is correct
22 Correct 23 ms 4940 KB Output is correct
23 Correct 14 ms 3544 KB Output is correct
24 Correct 30 ms 6220 KB Output is correct
25 Correct 27 ms 6224 KB Output is correct
26 Correct 41 ms 6596 KB Output is correct
27 Correct 31 ms 6656 KB Output is correct
28 Correct 30 ms 6580 KB Output is correct
29 Correct 31 ms 6604 KB Output is correct
30 Correct 30 ms 6476 KB Output is correct
31 Correct 40 ms 6596 KB Output is correct
32 Correct 30 ms 6596 KB Output is correct
33 Correct 31 ms 6476 KB Output is correct
34 Correct 33 ms 6476 KB Output is correct
35 Correct 32 ms 6604 KB Output is correct
36 Correct 31 ms 6600 KB Output is correct
37 Correct 107 ms 12704 KB Output is correct
38 Correct 104 ms 12700 KB Output is correct
39 Correct 166 ms 15632 KB Output is correct
40 Correct 222 ms 17080 KB Output is correct
41 Correct 194 ms 16984 KB Output is correct
42 Correct 183 ms 15764 KB Output is correct
43 Correct 164 ms 15528 KB Output is correct
44 Correct 158 ms 15748 KB Output is correct
45 Correct 190 ms 15888 KB Output is correct
46 Correct 191 ms 16992 KB Output is correct
47 Correct 161 ms 15760 KB Output is correct
48 Correct 164 ms 15812 KB Output is correct
49 Correct 158 ms 15764 KB Output is correct
50 Correct 191 ms 15760 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 184 ms 17120 KB Output is correct
53 Correct 245 ms 18944 KB Output is correct
54 Correct 359 ms 22004 KB Output is correct
55 Correct 362 ms 22144 KB Output is correct
56 Correct 226 ms 19316 KB Output is correct
57 Correct 320 ms 22136 KB Output is correct
58 Correct 299 ms 22004 KB Output is correct
59 Correct 301 ms 21992 KB Output is correct
60 Correct 4 ms 460 KB Output is correct
61 Correct 296 ms 22008 KB Output is correct
62 Correct 295 ms 20300 KB Output is correct
63 Correct 259 ms 20292 KB Output is correct
64 Correct 258 ms 19928 KB Output is correct
65 Correct 246 ms 19908 KB Output is correct
66 Correct 230 ms 19436 KB Output is correct
67 Correct 394 ms 25068 KB Output is correct
68 Correct 5 ms 460 KB Output is correct
69 Correct 611 ms 31692 KB Output is correct
70 Correct 641 ms 31440 KB Output is correct
71 Correct 585 ms 31444 KB Output is correct
72 Correct 579 ms 31052 KB Output is correct
73 Correct 574 ms 30996 KB Output is correct
74 Correct 581 ms 31572 KB Output is correct
75 Correct 609 ms 31448 KB Output is correct
76 Correct 593 ms 31700 KB Output is correct
77 Correct 587 ms 31704 KB Output is correct