답안 #1077072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077072 2024-08-26T22:19:17 Z xnqs Bootfall (IZhO17_bootfall) C++17
100 / 100
152 ms 3028 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstdint>

int x;
int arr[505];
uint32_t knapsack[125005];
int freq[250005];

void knapsack_add(int val) {
	for (int i = 125004; i >= val; i--) {
		knapsack[i] += knapsack[i-val];
	}
}

void knapsack_remove(int val) {
	for (int i = 0; i < 125005-val; i++) {
		knapsack[i+val] -= knapsack[i];
	}
}

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	std::cin >> x;

	int sum = 0;
	knapsack[0] = 1;
	for (int i = 1; i <= x; i++) {
		std::cin >> arr[i];
		sum += arr[i];
		knapsack_add(arr[i]);
	}

	if (sum%2==1) {
		std::cout << "0\n";
		return 0;
	}
	if (!knapsack[sum/2]) {
		std::cout << "0\n";
		return 0;
	}

	for (int i = x; i >= 1; i--) {
		sum -= arr[i];
		knapsack_remove(arr[i]);
		if (i+1<=x) {
			sum += arr[i+1];
			knapsack_add(arr[i+1]);
		}

		for (int i = 0; i <= sum/2; i++) {
			freq[sum-i-i] += !!knapsack[i];
		}
	}

	std::vector<int> ret;
	for (int i = 1; i < 250005; i++) {
		if (freq[i]==x) {
			ret.emplace_back(i);
		}
	}

	std::cout << ret.size() << "\n";
	for (const auto& i : ret) {
		std::cout << i << " ";
	}
	std::cout << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 7 ms 856 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 6 ms 956 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 7 ms 956 KB Output is correct
17 Correct 5 ms 956 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 956 KB Output is correct
20 Correct 8 ms 1096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 7 ms 856 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 6 ms 956 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 7 ms 956 KB Output is correct
17 Correct 5 ms 956 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 956 KB Output is correct
20 Correct 8 ms 1096 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 15 ms 964 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 19 ms 860 KB Output is correct
25 Correct 18 ms 860 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 27 ms 976 KB Output is correct
28 Correct 20 ms 856 KB Output is correct
29 Correct 21 ms 992 KB Output is correct
30 Correct 26 ms 1112 KB Output is correct
31 Correct 20 ms 972 KB Output is correct
32 Correct 20 ms 952 KB Output is correct
33 Correct 20 ms 936 KB Output is correct
34 Correct 20 ms 956 KB Output is correct
35 Correct 20 ms 860 KB Output is correct
36 Correct 20 ms 968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 7 ms 856 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 6 ms 956 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 7 ms 956 KB Output is correct
17 Correct 5 ms 956 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 956 KB Output is correct
20 Correct 8 ms 1096 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 15 ms 964 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 19 ms 860 KB Output is correct
25 Correct 18 ms 860 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 27 ms 976 KB Output is correct
28 Correct 20 ms 856 KB Output is correct
29 Correct 21 ms 992 KB Output is correct
30 Correct 26 ms 1112 KB Output is correct
31 Correct 20 ms 972 KB Output is correct
32 Correct 20 ms 952 KB Output is correct
33 Correct 20 ms 936 KB Output is correct
34 Correct 20 ms 956 KB Output is correct
35 Correct 20 ms 860 KB Output is correct
36 Correct 20 ms 968 KB Output is correct
37 Correct 39 ms 1012 KB Output is correct
38 Correct 44 ms 1028 KB Output is correct
39 Correct 63 ms 1168 KB Output is correct
40 Correct 55 ms 1108 KB Output is correct
41 Correct 74 ms 1112 KB Output is correct
42 Correct 50 ms 1044 KB Output is correct
43 Correct 51 ms 1360 KB Output is correct
44 Correct 60 ms 1412 KB Output is correct
45 Correct 59 ms 1408 KB Output is correct
46 Correct 54 ms 860 KB Output is correct
47 Correct 51 ms 1104 KB Output is correct
48 Correct 52 ms 1428 KB Output is correct
49 Correct 51 ms 1212 KB Output is correct
50 Correct 50 ms 1080 KB Output is correct
51 Correct 14 ms 856 KB Output is correct
52 Correct 57 ms 1460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 7 ms 856 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 6 ms 956 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 7 ms 956 KB Output is correct
17 Correct 5 ms 956 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 956 KB Output is correct
20 Correct 8 ms 1096 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 15 ms 964 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 19 ms 860 KB Output is correct
25 Correct 18 ms 860 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 27 ms 976 KB Output is correct
28 Correct 20 ms 856 KB Output is correct
29 Correct 21 ms 992 KB Output is correct
30 Correct 26 ms 1112 KB Output is correct
31 Correct 20 ms 972 KB Output is correct
32 Correct 20 ms 952 KB Output is correct
33 Correct 20 ms 936 KB Output is correct
34 Correct 20 ms 956 KB Output is correct
35 Correct 20 ms 860 KB Output is correct
36 Correct 20 ms 968 KB Output is correct
37 Correct 39 ms 1012 KB Output is correct
38 Correct 44 ms 1028 KB Output is correct
39 Correct 63 ms 1168 KB Output is correct
40 Correct 55 ms 1108 KB Output is correct
41 Correct 74 ms 1112 KB Output is correct
42 Correct 50 ms 1044 KB Output is correct
43 Correct 51 ms 1360 KB Output is correct
44 Correct 60 ms 1412 KB Output is correct
45 Correct 59 ms 1408 KB Output is correct
46 Correct 54 ms 860 KB Output is correct
47 Correct 51 ms 1104 KB Output is correct
48 Correct 52 ms 1428 KB Output is correct
49 Correct 51 ms 1212 KB Output is correct
50 Correct 50 ms 1080 KB Output is correct
51 Correct 14 ms 856 KB Output is correct
52 Correct 57 ms 1460 KB Output is correct
53 Correct 62 ms 1364 KB Output is correct
54 Correct 72 ms 1408 KB Output is correct
55 Correct 105 ms 1748 KB Output is correct
56 Correct 63 ms 1364 KB Output is correct
57 Correct 78 ms 1996 KB Output is correct
58 Correct 78 ms 1428 KB Output is correct
59 Correct 87 ms 1632 KB Output is correct
60 Correct 18 ms 952 KB Output is correct
61 Correct 75 ms 1588 KB Output is correct
62 Correct 69 ms 1752 KB Output is correct
63 Correct 73 ms 1740 KB Output is correct
64 Correct 69 ms 1752 KB Output is correct
65 Correct 63 ms 1120 KB Output is correct
66 Correct 63 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 3 ms 860 KB Output is correct
9 Correct 2 ms 860 KB Output is correct
10 Correct 7 ms 856 KB Output is correct
11 Correct 7 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 6 ms 956 KB Output is correct
14 Correct 7 ms 860 KB Output is correct
15 Correct 6 ms 860 KB Output is correct
16 Correct 7 ms 956 KB Output is correct
17 Correct 5 ms 956 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 956 KB Output is correct
20 Correct 8 ms 1096 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 15 ms 964 KB Output is correct
23 Correct 11 ms 860 KB Output is correct
24 Correct 19 ms 860 KB Output is correct
25 Correct 18 ms 860 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 27 ms 976 KB Output is correct
28 Correct 20 ms 856 KB Output is correct
29 Correct 21 ms 992 KB Output is correct
30 Correct 26 ms 1112 KB Output is correct
31 Correct 20 ms 972 KB Output is correct
32 Correct 20 ms 952 KB Output is correct
33 Correct 20 ms 936 KB Output is correct
34 Correct 20 ms 956 KB Output is correct
35 Correct 20 ms 860 KB Output is correct
36 Correct 20 ms 968 KB Output is correct
37 Correct 39 ms 1012 KB Output is correct
38 Correct 44 ms 1028 KB Output is correct
39 Correct 63 ms 1168 KB Output is correct
40 Correct 55 ms 1108 KB Output is correct
41 Correct 74 ms 1112 KB Output is correct
42 Correct 50 ms 1044 KB Output is correct
43 Correct 51 ms 1360 KB Output is correct
44 Correct 60 ms 1412 KB Output is correct
45 Correct 59 ms 1408 KB Output is correct
46 Correct 54 ms 860 KB Output is correct
47 Correct 51 ms 1104 KB Output is correct
48 Correct 52 ms 1428 KB Output is correct
49 Correct 51 ms 1212 KB Output is correct
50 Correct 50 ms 1080 KB Output is correct
51 Correct 14 ms 856 KB Output is correct
52 Correct 57 ms 1460 KB Output is correct
53 Correct 62 ms 1364 KB Output is correct
54 Correct 72 ms 1408 KB Output is correct
55 Correct 105 ms 1748 KB Output is correct
56 Correct 63 ms 1364 KB Output is correct
57 Correct 78 ms 1996 KB Output is correct
58 Correct 78 ms 1428 KB Output is correct
59 Correct 87 ms 1632 KB Output is correct
60 Correct 18 ms 952 KB Output is correct
61 Correct 75 ms 1588 KB Output is correct
62 Correct 69 ms 1752 KB Output is correct
63 Correct 73 ms 1740 KB Output is correct
64 Correct 69 ms 1752 KB Output is correct
65 Correct 63 ms 1120 KB Output is correct
66 Correct 63 ms 1112 KB Output is correct
67 Correct 85 ms 1592 KB Output is correct
68 Correct 26 ms 856 KB Output is correct
69 Correct 125 ms 2772 KB Output is correct
70 Correct 113 ms 2008 KB Output is correct
71 Correct 121 ms 2068 KB Output is correct
72 Correct 111 ms 1360 KB Output is correct
73 Correct 110 ms 1368 KB Output is correct
74 Correct 127 ms 3028 KB Output is correct
75 Correct 119 ms 2512 KB Output is correct
76 Correct 131 ms 3028 KB Output is correct
77 Correct 152 ms 3028 KB Output is correct