Submission #342626

# Submission time Handle Problem Language Result Execution time Memory
342626 2021-01-02T13:55:29 Z Sorting Bootfall (IZhO17_bootfall) C++17
100 / 100
131 ms 18988 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 500 + 3;

int n, a[N], sum;
bitset<N * N> dp[N];
int is_ans[N * N];
vector<int> ans;

void dnc(int l, int r, const bitset<N * N> &b){
    if(l == r) dp[l] = b;
    else{
        int mid = (l + r) >> 1;
        bitset<N * N> new_b;

        new_b = b;
        for(int i = l; i <= mid; ++i)
            new_b |= new_b << a[i];

        dnc(mid + 1, r, new_b);

        new_b = b;
        for(int i = mid + 1; i <= r; ++i)
            new_b |= new_b << a[i];
    
        dnc(l, mid, new_b);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    a[n] = 0;

    if(sum & 1){
        cout << "0\n";
        return 0;
    }

    bitset<N * N> curr;
    curr[0] = 1;
    dnc(0, n, curr);

    if(!dp[n][(sum >> 1)]){
        cout << "0\n";
        return 0;
    }

    for(int i = 0; i < n; ++i){
        for(int j = (sum - a[i]) & 1; j <= sum; j += 2){
            int new_sum = sum - a[i] + j;
            if(dp[i][(new_sum >> 1)])
                is_ans[j]++;
        }
    }

    for(int i = 0; i <= sum; ++i)
        if(is_ans[i] == n)
            ans.push_back(i);

    cout << ans.size() << "\n";
    for(int x: ans)
        cout << x << " ";
    cout << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1900 KB Output is correct
16 Correct 3 ms 1772 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 3 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1900 KB Output is correct
16 Correct 3 ms 1772 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 3 ms 1772 KB Output is correct
21 Correct 6 ms 3052 KB Output is correct
22 Correct 7 ms 3436 KB Output is correct
23 Correct 5 ms 2540 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 9 ms 4076 KB Output is correct
26 Correct 10 ms 4204 KB Output is correct
27 Correct 10 ms 4204 KB Output is correct
28 Correct 10 ms 4204 KB Output is correct
29 Correct 10 ms 4224 KB Output is correct
30 Correct 10 ms 4204 KB Output is correct
31 Correct 10 ms 4204 KB Output is correct
32 Correct 9 ms 4204 KB Output is correct
33 Correct 10 ms 4204 KB Output is correct
34 Correct 10 ms 4204 KB Output is correct
35 Correct 10 ms 4204 KB Output is correct
36 Correct 9 ms 4204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1900 KB Output is correct
16 Correct 3 ms 1772 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 3 ms 1772 KB Output is correct
21 Correct 6 ms 3052 KB Output is correct
22 Correct 7 ms 3436 KB Output is correct
23 Correct 5 ms 2540 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 9 ms 4076 KB Output is correct
26 Correct 10 ms 4204 KB Output is correct
27 Correct 10 ms 4204 KB Output is correct
28 Correct 10 ms 4204 KB Output is correct
29 Correct 10 ms 4224 KB Output is correct
30 Correct 10 ms 4204 KB Output is correct
31 Correct 10 ms 4204 KB Output is correct
32 Correct 9 ms 4204 KB Output is correct
33 Correct 10 ms 4204 KB Output is correct
34 Correct 10 ms 4204 KB Output is correct
35 Correct 10 ms 4204 KB Output is correct
36 Correct 9 ms 4204 KB Output is correct
37 Correct 23 ms 7660 KB Output is correct
38 Correct 22 ms 7532 KB Output is correct
39 Correct 32 ms 9068 KB Output is correct
40 Correct 45 ms 9964 KB Output is correct
41 Correct 37 ms 9836 KB Output is correct
42 Correct 30 ms 9244 KB Output is correct
43 Correct 34 ms 9324 KB Output is correct
44 Correct 34 ms 9452 KB Output is correct
45 Correct 34 ms 9452 KB Output is correct
46 Correct 30 ms 9708 KB Output is correct
47 Correct 30 ms 9212 KB Output is correct
48 Correct 35 ms 9452 KB Output is correct
49 Correct 34 ms 9196 KB Output is correct
50 Correct 30 ms 9196 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 40 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1900 KB Output is correct
16 Correct 3 ms 1772 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 3 ms 1772 KB Output is correct
21 Correct 6 ms 3052 KB Output is correct
22 Correct 7 ms 3436 KB Output is correct
23 Correct 5 ms 2540 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 9 ms 4076 KB Output is correct
26 Correct 10 ms 4204 KB Output is correct
27 Correct 10 ms 4204 KB Output is correct
28 Correct 10 ms 4204 KB Output is correct
29 Correct 10 ms 4224 KB Output is correct
30 Correct 10 ms 4204 KB Output is correct
31 Correct 10 ms 4204 KB Output is correct
32 Correct 9 ms 4204 KB Output is correct
33 Correct 10 ms 4204 KB Output is correct
34 Correct 10 ms 4204 KB Output is correct
35 Correct 10 ms 4204 KB Output is correct
36 Correct 9 ms 4204 KB Output is correct
37 Correct 23 ms 7660 KB Output is correct
38 Correct 22 ms 7532 KB Output is correct
39 Correct 32 ms 9068 KB Output is correct
40 Correct 45 ms 9964 KB Output is correct
41 Correct 37 ms 9836 KB Output is correct
42 Correct 30 ms 9244 KB Output is correct
43 Correct 34 ms 9324 KB Output is correct
44 Correct 34 ms 9452 KB Output is correct
45 Correct 34 ms 9452 KB Output is correct
46 Correct 30 ms 9708 KB Output is correct
47 Correct 30 ms 9212 KB Output is correct
48 Correct 35 ms 9452 KB Output is correct
49 Correct 34 ms 9196 KB Output is correct
50 Correct 30 ms 9196 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 40 ms 10348 KB Output is correct
53 Correct 39 ms 11024 KB Output is correct
54 Correct 48 ms 12652 KB Output is correct
55 Correct 64 ms 13168 KB Output is correct
56 Correct 42 ms 11372 KB Output is correct
57 Correct 75 ms 13168 KB Output is correct
58 Correct 50 ms 12780 KB Output is correct
59 Correct 56 ms 13040 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 56 ms 12912 KB Output is correct
62 Correct 54 ms 12140 KB Output is correct
63 Correct 54 ms 12144 KB Output is correct
64 Correct 54 ms 12016 KB Output is correct
65 Correct 44 ms 11244 KB Output is correct
66 Correct 40 ms 11116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 3 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1900 KB Output is correct
16 Correct 3 ms 1772 KB Output is correct
17 Correct 2 ms 1388 KB Output is correct
18 Correct 2 ms 1644 KB Output is correct
19 Correct 3 ms 1644 KB Output is correct
20 Correct 3 ms 1772 KB Output is correct
21 Correct 6 ms 3052 KB Output is correct
22 Correct 7 ms 3436 KB Output is correct
23 Correct 5 ms 2540 KB Output is correct
24 Correct 9 ms 4076 KB Output is correct
25 Correct 9 ms 4076 KB Output is correct
26 Correct 10 ms 4204 KB Output is correct
27 Correct 10 ms 4204 KB Output is correct
28 Correct 10 ms 4204 KB Output is correct
29 Correct 10 ms 4224 KB Output is correct
30 Correct 10 ms 4204 KB Output is correct
31 Correct 10 ms 4204 KB Output is correct
32 Correct 9 ms 4204 KB Output is correct
33 Correct 10 ms 4204 KB Output is correct
34 Correct 10 ms 4204 KB Output is correct
35 Correct 10 ms 4204 KB Output is correct
36 Correct 9 ms 4204 KB Output is correct
37 Correct 23 ms 7660 KB Output is correct
38 Correct 22 ms 7532 KB Output is correct
39 Correct 32 ms 9068 KB Output is correct
40 Correct 45 ms 9964 KB Output is correct
41 Correct 37 ms 9836 KB Output is correct
42 Correct 30 ms 9244 KB Output is correct
43 Correct 34 ms 9324 KB Output is correct
44 Correct 34 ms 9452 KB Output is correct
45 Correct 34 ms 9452 KB Output is correct
46 Correct 30 ms 9708 KB Output is correct
47 Correct 30 ms 9212 KB Output is correct
48 Correct 35 ms 9452 KB Output is correct
49 Correct 34 ms 9196 KB Output is correct
50 Correct 30 ms 9196 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 40 ms 10348 KB Output is correct
53 Correct 39 ms 11024 KB Output is correct
54 Correct 48 ms 12652 KB Output is correct
55 Correct 64 ms 13168 KB Output is correct
56 Correct 42 ms 11372 KB Output is correct
57 Correct 75 ms 13168 KB Output is correct
58 Correct 50 ms 12780 KB Output is correct
59 Correct 56 ms 13040 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 56 ms 12912 KB Output is correct
62 Correct 54 ms 12140 KB Output is correct
63 Correct 54 ms 12144 KB Output is correct
64 Correct 54 ms 12016 KB Output is correct
65 Correct 44 ms 11244 KB Output is correct
66 Correct 40 ms 11116 KB Output is correct
67 Correct 62 ms 14432 KB Output is correct
68 Correct 51 ms 16748 KB Output is correct
69 Correct 125 ms 18816 KB Output is correct
70 Correct 93 ms 18032 KB Output is correct
71 Correct 92 ms 18032 KB Output is correct
72 Correct 86 ms 17260 KB Output is correct
73 Correct 86 ms 17132 KB Output is correct
74 Correct 124 ms 18796 KB Output is correct
75 Correct 124 ms 18540 KB Output is correct
76 Correct 130 ms 18924 KB Output is correct
77 Correct 131 ms 18988 KB Output is correct