답안 #635753

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635753 2022-08-26T18:47:09 Z tvladm2009 Bootfall (IZhO17_bootfall) C++14
100 / 100
389 ms 5668 KB
#include <iostream>

using namespace std;

const int MAX_N = 500;
const int MOD = 1e9 + 7;
int a[MAX_N + 1], dp[MAX_N * MAX_N + 1], ways[MAX_N * MAX_N + 1], ways2[MAX_N * MAX_N + 1], cnt[MAX_N * MAX_N + 1], aux[MAX_N * MAX_N + 1];
int n;

void addSelf(int &a, int b) {
    a += b;
    if (a >= MOD) {
        a -= MOD;
    }
}

bool hentai(int pos) {
    int s = 0;
    for (int i = 1; i <= n; i++) {
        if (i != pos) {
            s += a[i];
        }
    }
    if (pos == 0) {
        dp[0] = true;
        ways[0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = s; j >= a[i]; j--) {
                dp[j] |= dp[j - a[i]];
                addSelf(ways[j], ways[j - a[i]]);
            }
        }
        if (s % 2 == 0 && dp[s / 2]) {
            return true;
        } else {
            return false;
        }
    } else {
        for (int i = 0; i <= s + a[pos]; i++) {
            ways2[i] = ways[i];
        }
        for (int i = a[pos]; i <= s + a[pos]; i++) {
            addSelf(ways[i], -ways[i - a[pos]]);
        }
        for (int i = 0; i <= s / 2; i++) {
            if (ways[i]) {
                cnt[s - 2 * i]++;
            }
        }
        for (int i = 0; i <= s + a[pos]; i++) {
            aux[i] = ways[i];
        }
        for (int i = 0; i <= s + a[pos]; i++) {
            ways[i] = ways2[i];
        }
        return true;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if (!hentai(0)) {
        cout << "0\n";
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        hentai(i);
    }
    int answer = 0;
    for (int i = 0; i <= MAX_N * MAX_N; i++) {
        if (cnt[i] == n) {
            answer++;
        }
    }
    cout << answer << "\n";
    for (int i = 0; i <= MAX_N * MAX_N; i++) {
        if (cnt[i] == n) {
            cout << i << " ";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 436 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 524 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 436 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 436 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 524 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 436 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 14 ms 692 KB Output is correct
38 Correct 13 ms 728 KB Output is correct
39 Correct 49 ms 1492 KB Output is correct
40 Correct 27 ms 960 KB Output is correct
41 Correct 56 ms 1740 KB Output is correct
42 Correct 23 ms 936 KB Output is correct
43 Correct 40 ms 1532 KB Output is correct
44 Correct 41 ms 1520 KB Output is correct
45 Correct 46 ms 1488 KB Output is correct
46 Correct 32 ms 940 KB Output is correct
47 Correct 30 ms 968 KB Output is correct
48 Correct 49 ms 1560 KB Output is correct
49 Correct 45 ms 1528 KB Output is correct
50 Correct 25 ms 968 KB Output is correct
51 Correct 10 ms 568 KB Output is correct
52 Correct 57 ms 1816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 436 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 524 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 436 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 14 ms 692 KB Output is correct
38 Correct 13 ms 728 KB Output is correct
39 Correct 49 ms 1492 KB Output is correct
40 Correct 27 ms 960 KB Output is correct
41 Correct 56 ms 1740 KB Output is correct
42 Correct 23 ms 936 KB Output is correct
43 Correct 40 ms 1532 KB Output is correct
44 Correct 41 ms 1520 KB Output is correct
45 Correct 46 ms 1488 KB Output is correct
46 Correct 32 ms 940 KB Output is correct
47 Correct 30 ms 968 KB Output is correct
48 Correct 49 ms 1560 KB Output is correct
49 Correct 45 ms 1528 KB Output is correct
50 Correct 25 ms 968 KB Output is correct
51 Correct 10 ms 568 KB Output is correct
52 Correct 57 ms 1816 KB Output is correct
53 Correct 41 ms 1312 KB Output is correct
54 Correct 66 ms 1524 KB Output is correct
55 Correct 118 ms 2708 KB Output is correct
56 Correct 51 ms 1524 KB Output is correct
57 Correct 119 ms 2864 KB Output is correct
58 Correct 68 ms 1612 KB Output is correct
59 Correct 86 ms 1960 KB Output is correct
60 Correct 26 ms 724 KB Output is correct
61 Correct 88 ms 2124 KB Output is correct
62 Correct 95 ms 2344 KB Output is correct
63 Correct 108 ms 2596 KB Output is correct
64 Correct 95 ms 2576 KB Output is correct
65 Correct 47 ms 1260 KB Output is correct
66 Correct 51 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 308 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 436 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 524 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 436 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 2 ms 436 KB Output is correct
37 Correct 14 ms 692 KB Output is correct
38 Correct 13 ms 728 KB Output is correct
39 Correct 49 ms 1492 KB Output is correct
40 Correct 27 ms 960 KB Output is correct
41 Correct 56 ms 1740 KB Output is correct
42 Correct 23 ms 936 KB Output is correct
43 Correct 40 ms 1532 KB Output is correct
44 Correct 41 ms 1520 KB Output is correct
45 Correct 46 ms 1488 KB Output is correct
46 Correct 32 ms 940 KB Output is correct
47 Correct 30 ms 968 KB Output is correct
48 Correct 49 ms 1560 KB Output is correct
49 Correct 45 ms 1528 KB Output is correct
50 Correct 25 ms 968 KB Output is correct
51 Correct 10 ms 568 KB Output is correct
52 Correct 57 ms 1816 KB Output is correct
53 Correct 41 ms 1312 KB Output is correct
54 Correct 66 ms 1524 KB Output is correct
55 Correct 118 ms 2708 KB Output is correct
56 Correct 51 ms 1524 KB Output is correct
57 Correct 119 ms 2864 KB Output is correct
58 Correct 68 ms 1612 KB Output is correct
59 Correct 86 ms 1960 KB Output is correct
60 Correct 26 ms 724 KB Output is correct
61 Correct 88 ms 2124 KB Output is correct
62 Correct 95 ms 2344 KB Output is correct
63 Correct 108 ms 2596 KB Output is correct
64 Correct 95 ms 2576 KB Output is correct
65 Correct 47 ms 1260 KB Output is correct
66 Correct 51 ms 1356 KB Output is correct
67 Correct 97 ms 2000 KB Output is correct
68 Correct 71 ms 1264 KB Output is correct
69 Correct 313 ms 5028 KB Output is correct
70 Correct 196 ms 3196 KB Output is correct
71 Correct 181 ms 3020 KB Output is correct
72 Correct 198 ms 2756 KB Output is correct
73 Correct 182 ms 2696 KB Output is correct
74 Correct 329 ms 5324 KB Output is correct
75 Correct 259 ms 4156 KB Output is correct
76 Correct 361 ms 5668 KB Output is correct
77 Correct 389 ms 5608 KB Output is correct