답안 #170498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170498 2019-12-25T13:40:59 Z mcdx9524 Bootfall (IZhO17_bootfall) C++14
100 / 100
458 ms 3700 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 500 * 500 + 7;
const int mod = 1e9 + 7;

int dp[N];
int can[N];

void add(int x) {
    for (int i = N - x - 1; i >= 0; i--) {
        dp[i + x] = dp[i + x] + dp[i];
    }
}

void rem(int x) {
    for (int i = x; i < N; i++) {
        dp[i] = dp[i] - dp[i - x];
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0] = 1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        add(a[i]);
        sum += a[i];
    }
    if (!dp[sum / 2]) {
        cout << 0 << '\n';
        return 0;
    }
    for (int i = 0; i < n; i++) {
        sum -= a[i];
        rem(a[i]);
        for (int j = 0; j < N; j++) {
            if (dp[j]) {
                can[abs(sum - 2 * j)]++;
            }
        }
        sum += a[i];
        add(a[i]);
    }
    vector <int> res;
    for (int i = 1; i < N; i++) {
        if (can[i] == 2 * n) {
            res.push_back(i);
        }
    }
    cout << (int) res.size() << '\n';
    for (int x : res) {
        cout << x << ' ';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 25 ms 1400 KB Output is correct
11 Correct 27 ms 1400 KB Output is correct
12 Correct 25 ms 1272 KB Output is correct
13 Correct 23 ms 1272 KB Output is correct
14 Correct 25 ms 1400 KB Output is correct
15 Correct 26 ms 1400 KB Output is correct
16 Correct 27 ms 1272 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 23 ms 1272 KB Output is correct
20 Correct 25 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 25 ms 1400 KB Output is correct
11 Correct 27 ms 1400 KB Output is correct
12 Correct 25 ms 1272 KB Output is correct
13 Correct 23 ms 1272 KB Output is correct
14 Correct 25 ms 1400 KB Output is correct
15 Correct 26 ms 1400 KB Output is correct
16 Correct 27 ms 1272 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 23 ms 1272 KB Output is correct
20 Correct 25 ms 1400 KB Output is correct
21 Correct 49 ms 1400 KB Output is correct
22 Correct 56 ms 1400 KB Output is correct
23 Correct 40 ms 1400 KB Output is correct
24 Correct 71 ms 1400 KB Output is correct
25 Correct 70 ms 1528 KB Output is correct
26 Correct 74 ms 1432 KB Output is correct
27 Correct 73 ms 1400 KB Output is correct
28 Correct 73 ms 1396 KB Output is correct
29 Correct 73 ms 1400 KB Output is correct
30 Correct 74 ms 1400 KB Output is correct
31 Correct 74 ms 1404 KB Output is correct
32 Correct 74 ms 1376 KB Output is correct
33 Correct 73 ms 1400 KB Output is correct
34 Correct 73 ms 1400 KB Output is correct
35 Correct 73 ms 1400 KB Output is correct
36 Correct 75 ms 1508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 25 ms 1400 KB Output is correct
11 Correct 27 ms 1400 KB Output is correct
12 Correct 25 ms 1272 KB Output is correct
13 Correct 23 ms 1272 KB Output is correct
14 Correct 25 ms 1400 KB Output is correct
15 Correct 26 ms 1400 KB Output is correct
16 Correct 27 ms 1272 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 23 ms 1272 KB Output is correct
20 Correct 25 ms 1400 KB Output is correct
21 Correct 49 ms 1400 KB Output is correct
22 Correct 56 ms 1400 KB Output is correct
23 Correct 40 ms 1400 KB Output is correct
24 Correct 71 ms 1400 KB Output is correct
25 Correct 70 ms 1528 KB Output is correct
26 Correct 74 ms 1432 KB Output is correct
27 Correct 73 ms 1400 KB Output is correct
28 Correct 73 ms 1396 KB Output is correct
29 Correct 73 ms 1400 KB Output is correct
30 Correct 74 ms 1400 KB Output is correct
31 Correct 74 ms 1404 KB Output is correct
32 Correct 74 ms 1376 KB Output is correct
33 Correct 73 ms 1400 KB Output is correct
34 Correct 73 ms 1400 KB Output is correct
35 Correct 73 ms 1400 KB Output is correct
36 Correct 75 ms 1508 KB Output is correct
37 Correct 145 ms 1528 KB Output is correct
38 Correct 146 ms 1656 KB Output is correct
39 Correct 176 ms 1636 KB Output is correct
40 Correct 199 ms 1656 KB Output is correct
41 Correct 190 ms 1656 KB Output is correct
42 Correct 184 ms 1628 KB Output is correct
43 Correct 186 ms 2012 KB Output is correct
44 Correct 189 ms 1912 KB Output is correct
45 Correct 190 ms 2004 KB Output is correct
46 Correct 192 ms 1480 KB Output is correct
47 Correct 186 ms 1656 KB Output is correct
48 Correct 190 ms 1892 KB Output is correct
49 Correct 183 ms 1604 KB Output is correct
50 Correct 186 ms 1616 KB Output is correct
51 Correct 183 ms 1480 KB Output is correct
52 Correct 209 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 25 ms 1400 KB Output is correct
11 Correct 27 ms 1400 KB Output is correct
12 Correct 25 ms 1272 KB Output is correct
13 Correct 23 ms 1272 KB Output is correct
14 Correct 25 ms 1400 KB Output is correct
15 Correct 26 ms 1400 KB Output is correct
16 Correct 27 ms 1272 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 23 ms 1272 KB Output is correct
20 Correct 25 ms 1400 KB Output is correct
21 Correct 49 ms 1400 KB Output is correct
22 Correct 56 ms 1400 KB Output is correct
23 Correct 40 ms 1400 KB Output is correct
24 Correct 71 ms 1400 KB Output is correct
25 Correct 70 ms 1528 KB Output is correct
26 Correct 74 ms 1432 KB Output is correct
27 Correct 73 ms 1400 KB Output is correct
28 Correct 73 ms 1396 KB Output is correct
29 Correct 73 ms 1400 KB Output is correct
30 Correct 74 ms 1400 KB Output is correct
31 Correct 74 ms 1404 KB Output is correct
32 Correct 74 ms 1376 KB Output is correct
33 Correct 73 ms 1400 KB Output is correct
34 Correct 73 ms 1400 KB Output is correct
35 Correct 73 ms 1400 KB Output is correct
36 Correct 75 ms 1508 KB Output is correct
37 Correct 145 ms 1528 KB Output is correct
38 Correct 146 ms 1656 KB Output is correct
39 Correct 176 ms 1636 KB Output is correct
40 Correct 199 ms 1656 KB Output is correct
41 Correct 190 ms 1656 KB Output is correct
42 Correct 184 ms 1628 KB Output is correct
43 Correct 186 ms 2012 KB Output is correct
44 Correct 189 ms 1912 KB Output is correct
45 Correct 190 ms 2004 KB Output is correct
46 Correct 192 ms 1480 KB Output is correct
47 Correct 186 ms 1656 KB Output is correct
48 Correct 190 ms 1892 KB Output is correct
49 Correct 183 ms 1604 KB Output is correct
50 Correct 186 ms 1616 KB Output is correct
51 Correct 183 ms 1480 KB Output is correct
52 Correct 209 ms 2124 KB Output is correct
53 Correct 225 ms 1804 KB Output is correct
54 Correct 265 ms 1960 KB Output is correct
55 Correct 281 ms 2424 KB Output is correct
56 Correct 231 ms 2040 KB Output is correct
57 Correct 284 ms 2492 KB Output is correct
58 Correct 268 ms 2024 KB Output is correct
59 Correct 271 ms 2084 KB Output is correct
60 Correct 263 ms 1528 KB Output is correct
61 Correct 276 ms 2236 KB Output is correct
62 Correct 256 ms 2296 KB Output is correct
63 Correct 256 ms 2296 KB Output is correct
64 Correct 250 ms 2440 KB Output is correct
65 Correct 228 ms 1588 KB Output is correct
66 Correct 219 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1276 KB Output is correct
2 Correct 8 ms 1272 KB Output is correct
3 Correct 3 ms 1272 KB Output is correct
4 Correct 7 ms 1272 KB Output is correct
5 Correct 13 ms 1400 KB Output is correct
6 Correct 10 ms 1272 KB Output is correct
7 Correct 8 ms 1272 KB Output is correct
8 Correct 12 ms 1400 KB Output is correct
9 Correct 11 ms 1272 KB Output is correct
10 Correct 25 ms 1400 KB Output is correct
11 Correct 27 ms 1400 KB Output is correct
12 Correct 25 ms 1272 KB Output is correct
13 Correct 23 ms 1272 KB Output is correct
14 Correct 25 ms 1400 KB Output is correct
15 Correct 26 ms 1400 KB Output is correct
16 Correct 27 ms 1272 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct
18 Correct 21 ms 1272 KB Output is correct
19 Correct 23 ms 1272 KB Output is correct
20 Correct 25 ms 1400 KB Output is correct
21 Correct 49 ms 1400 KB Output is correct
22 Correct 56 ms 1400 KB Output is correct
23 Correct 40 ms 1400 KB Output is correct
24 Correct 71 ms 1400 KB Output is correct
25 Correct 70 ms 1528 KB Output is correct
26 Correct 74 ms 1432 KB Output is correct
27 Correct 73 ms 1400 KB Output is correct
28 Correct 73 ms 1396 KB Output is correct
29 Correct 73 ms 1400 KB Output is correct
30 Correct 74 ms 1400 KB Output is correct
31 Correct 74 ms 1404 KB Output is correct
32 Correct 74 ms 1376 KB Output is correct
33 Correct 73 ms 1400 KB Output is correct
34 Correct 73 ms 1400 KB Output is correct
35 Correct 73 ms 1400 KB Output is correct
36 Correct 75 ms 1508 KB Output is correct
37 Correct 145 ms 1528 KB Output is correct
38 Correct 146 ms 1656 KB Output is correct
39 Correct 176 ms 1636 KB Output is correct
40 Correct 199 ms 1656 KB Output is correct
41 Correct 190 ms 1656 KB Output is correct
42 Correct 184 ms 1628 KB Output is correct
43 Correct 186 ms 2012 KB Output is correct
44 Correct 189 ms 1912 KB Output is correct
45 Correct 190 ms 2004 KB Output is correct
46 Correct 192 ms 1480 KB Output is correct
47 Correct 186 ms 1656 KB Output is correct
48 Correct 190 ms 1892 KB Output is correct
49 Correct 183 ms 1604 KB Output is correct
50 Correct 186 ms 1616 KB Output is correct
51 Correct 183 ms 1480 KB Output is correct
52 Correct 209 ms 2124 KB Output is correct
53 Correct 225 ms 1804 KB Output is correct
54 Correct 265 ms 1960 KB Output is correct
55 Correct 281 ms 2424 KB Output is correct
56 Correct 231 ms 2040 KB Output is correct
57 Correct 284 ms 2492 KB Output is correct
58 Correct 268 ms 2024 KB Output is correct
59 Correct 271 ms 2084 KB Output is correct
60 Correct 263 ms 1528 KB Output is correct
61 Correct 276 ms 2236 KB Output is correct
62 Correct 256 ms 2296 KB Output is correct
63 Correct 256 ms 2296 KB Output is correct
64 Correct 250 ms 2440 KB Output is correct
65 Correct 228 ms 1588 KB Output is correct
66 Correct 219 ms 1656 KB Output is correct
67 Correct 311 ms 2216 KB Output is correct
68 Correct 81 ms 1272 KB Output is correct
69 Correct 449 ms 3288 KB Output is correct
70 Correct 410 ms 2668 KB Output is correct
71 Correct 408 ms 2552 KB Output is correct
72 Correct 404 ms 1912 KB Output is correct
73 Correct 401 ms 1784 KB Output is correct
74 Correct 452 ms 3700 KB Output is correct
75 Correct 429 ms 3060 KB Output is correct
76 Correct 454 ms 3572 KB Output is correct
77 Correct 458 ms 3572 KB Output is correct