답안 #331698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331698 2020-11-29T15:53:40 Z vitkishloh228 Bootfall (IZhO17_bootfall) C++14
28 / 100
13 ms 748 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxc = 30000;
int S;
bitset<maxc> ans, q;
vector<int> a;
void solve(int l,int r,bitset<maxc> b) {
    if (l == r) {
        q.reset();
        for (int j = 0; j < maxc; ++j) {
            int needsum = (S - 2 * j - a[l]);
            if (needsum < 0) continue;
            if (b[j]) {
                q[needsum] = 1;
            }
        }
        ans &= q;
        return;
    }
    int m = (l + r) >> 1;
    bitset<maxc> l1, r1;
    l1 = b;
    r1 = b;
    for (int i = l; i <= m; ++i) {
        l1 |= l1 << a[i];
    }
    for (int i = m + 1; i <= r; ++i) {
        r1 |= r1 << a[i];
    }
    solve(l, m, r1);
    solve(m + 1, r, l1);
}
int main() {
    int n;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        S += a[i];
    }
    for (int i = 0; i < maxc; ++i) ans[i] = 1;
    bitset<maxc> cur;
    cur[0] = 1;
    solve(0, n - 1, cur);
    for (int i = 0; i < n; ++i) {
        cur |= cur << a[i];
    }
    if (S % 2 || !cur[S / 2]) {
        cout << 0;
        return 0;
    }
    vector<int> answer;
    for (int i = 1; i < maxc; ++i) {
        if (ans[i]) answer.push_back(i);
    }
    cout << answer.size() << '\n';
    for (auto elem : answer) cout << elem << ' ';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 6 ms 492 KB Output is correct
27 Correct 5 ms 492 KB Output is correct
28 Correct 5 ms 492 KB Output is correct
29 Correct 5 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 6 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 5 ms 492 KB Output is correct
36 Correct 5 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 6 ms 492 KB Output is correct
27 Correct 5 ms 492 KB Output is correct
28 Correct 5 ms 492 KB Output is correct
29 Correct 5 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 6 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 5 ms 492 KB Output is correct
36 Correct 5 ms 492 KB Output is correct
37 Correct 12 ms 748 KB Output is correct
38 Correct 13 ms 620 KB Output is correct
39 Incorrect 11 ms 492 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 6 ms 492 KB Output is correct
27 Correct 5 ms 492 KB Output is correct
28 Correct 5 ms 492 KB Output is correct
29 Correct 5 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 6 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 5 ms 492 KB Output is correct
36 Correct 5 ms 492 KB Output is correct
37 Correct 12 ms 748 KB Output is correct
38 Correct 13 ms 620 KB Output is correct
39 Incorrect 11 ms 492 KB Output isn't correct
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 4 ms 492 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 5 ms 492 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 6 ms 492 KB Output is correct
27 Correct 5 ms 492 KB Output is correct
28 Correct 5 ms 492 KB Output is correct
29 Correct 5 ms 492 KB Output is correct
30 Correct 5 ms 492 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 6 ms 492 KB Output is correct
33 Correct 5 ms 492 KB Output is correct
34 Correct 5 ms 492 KB Output is correct
35 Correct 5 ms 492 KB Output is correct
36 Correct 5 ms 492 KB Output is correct
37 Correct 12 ms 748 KB Output is correct
38 Correct 13 ms 620 KB Output is correct
39 Incorrect 11 ms 492 KB Output isn't correct
40 Halted 0 ms 0 KB -