답안 #331695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
331695 2020-11-29T15:52:22 Z vitkishloh228 Bootfall (IZhO17_bootfall) C++14
28 / 100
4 ms 620 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxc = 10000;
int S;
bitset<maxc> ans;
vector<int> a;
void solve(int l,int r,bitset<maxc> b) {
    if (l == r) {
        bitset<maxc> q;
        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 384 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 384 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 3 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 3 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 3 ms 364 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 3 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 3 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 3 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 3 ms 364 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 3 ms 364 KB Output is correct
37 Runtime error 2 ms 620 KB Execution killed with signal 6 (could be triggered by violating memory limits)
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 3 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 3 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 3 ms 364 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 3 ms 364 KB Output is correct
37 Runtime error 2 ms 620 KB Execution killed with signal 6 (could be triggered by violating memory limits)
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 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 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 2 ms 364 KB Output is correct
25 Correct 3 ms 364 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 3 ms 364 KB Output is correct
29 Correct 4 ms 364 KB Output is correct
30 Correct 3 ms 364 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 3 ms 364 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 2 ms 364 KB Output is correct
35 Correct 2 ms 364 KB Output is correct
36 Correct 3 ms 364 KB Output is correct
37 Runtime error 2 ms 620 KB Execution killed with signal 6 (could be triggered by violating memory limits)
38 Halted 0 ms 0 KB -