Submission #480595

# Submission time Handle Problem Language Result Execution time Memory
480595 2021-10-17T08:30:10 Z pure_mem Bootfall (IZhO17_bootfall) C++14
100 / 100
128 ms 4132 KB
#pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx2")

#include <iostream>
#include <bitset>
#include <vector>

#define X first
#define Y second
#define ll long long 
#define MP make_pair

using namespace std;

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

typedef bitset<N * N + 1> DP;

int n, sum, w[N];
int ans[N * N + 1];
DP cur;

void rec(int l, int r, DP cur) {
	if(r - l == 1) {
		for(int i = 0, j = sum - w[l];i <= j;i++, j--) {
			if(cur[i]) ans[j - i] += 1;
		} 
	}
	else {
		DP L = cur, R = cur;
		int m = (l + r) / 2;
		for(int i = l;i < r;i++) {
			if(i >= m) 
				R |= R << w[i];
			else 
				L |= L << w[i];
		}
		rec(l, m, R), rec(m, r, L);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for(int i = 0;i < n;i++)
		cin >> w[i], sum += w[i];
	
	DP cur = 1;
	for(int i = 0;i < n;i++)
		cur |= cur << w[i];
	if(cur[sum / 2] == 0) return cout << "0", 0;
	rec(0, n, DP(1));

	vector< int > res;
	for(int i = 0;i < N * N + 1;i++)
		if(ans[i] == n)
			res.push_back(i);
	
	cout << res.size() << "\n";
	for(int i: res)
		cout << i << " ";
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 4 ms 1300 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1228 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 3 ms 1304 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 4 ms 1300 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1228 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 3 ms 1304 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
21 Correct 5 ms 1456 KB Output is correct
22 Correct 5 ms 1644 KB Output is correct
23 Correct 4 ms 1484 KB Output is correct
24 Correct 7 ms 1612 KB Output is correct
25 Correct 8 ms 1612 KB Output is correct
26 Correct 8 ms 1612 KB Output is correct
27 Correct 7 ms 1668 KB Output is correct
28 Correct 8 ms 1612 KB Output is correct
29 Correct 7 ms 1612 KB Output is correct
30 Correct 7 ms 1660 KB Output is correct
31 Correct 8 ms 1612 KB Output is correct
32 Correct 7 ms 1612 KB Output is correct
33 Correct 7 ms 1676 KB Output is correct
34 Correct 7 ms 1676 KB Output is correct
35 Correct 9 ms 1612 KB Output is correct
36 Correct 8 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 4 ms 1300 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1228 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 3 ms 1304 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
21 Correct 5 ms 1456 KB Output is correct
22 Correct 5 ms 1644 KB Output is correct
23 Correct 4 ms 1484 KB Output is correct
24 Correct 7 ms 1612 KB Output is correct
25 Correct 8 ms 1612 KB Output is correct
26 Correct 8 ms 1612 KB Output is correct
27 Correct 7 ms 1668 KB Output is correct
28 Correct 8 ms 1612 KB Output is correct
29 Correct 7 ms 1612 KB Output is correct
30 Correct 7 ms 1660 KB Output is correct
31 Correct 8 ms 1612 KB Output is correct
32 Correct 7 ms 1612 KB Output is correct
33 Correct 7 ms 1676 KB Output is correct
34 Correct 7 ms 1676 KB Output is correct
35 Correct 9 ms 1612 KB Output is correct
36 Correct 8 ms 1644 KB Output is correct
37 Correct 16 ms 1996 KB Output is correct
38 Correct 20 ms 1992 KB Output is correct
39 Correct 26 ms 1996 KB Output is correct
40 Correct 28 ms 2212 KB Output is correct
41 Correct 27 ms 2124 KB Output is correct
42 Correct 23 ms 2036 KB Output is correct
43 Correct 26 ms 2368 KB Output is correct
44 Correct 35 ms 2368 KB Output is correct
45 Correct 27 ms 2264 KB Output is correct
46 Correct 25 ms 2044 KB Output is correct
47 Correct 24 ms 2036 KB Output is correct
48 Correct 29 ms 2292 KB Output is correct
49 Correct 28 ms 2024 KB Output is correct
50 Correct 25 ms 2020 KB Output is correct
51 Correct 23 ms 1868 KB Output is correct
52 Correct 33 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 4 ms 1300 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1228 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 3 ms 1304 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
21 Correct 5 ms 1456 KB Output is correct
22 Correct 5 ms 1644 KB Output is correct
23 Correct 4 ms 1484 KB Output is correct
24 Correct 7 ms 1612 KB Output is correct
25 Correct 8 ms 1612 KB Output is correct
26 Correct 8 ms 1612 KB Output is correct
27 Correct 7 ms 1668 KB Output is correct
28 Correct 8 ms 1612 KB Output is correct
29 Correct 7 ms 1612 KB Output is correct
30 Correct 7 ms 1660 KB Output is correct
31 Correct 8 ms 1612 KB Output is correct
32 Correct 7 ms 1612 KB Output is correct
33 Correct 7 ms 1676 KB Output is correct
34 Correct 7 ms 1676 KB Output is correct
35 Correct 9 ms 1612 KB Output is correct
36 Correct 8 ms 1644 KB Output is correct
37 Correct 16 ms 1996 KB Output is correct
38 Correct 20 ms 1992 KB Output is correct
39 Correct 26 ms 1996 KB Output is correct
40 Correct 28 ms 2212 KB Output is correct
41 Correct 27 ms 2124 KB Output is correct
42 Correct 23 ms 2036 KB Output is correct
43 Correct 26 ms 2368 KB Output is correct
44 Correct 35 ms 2368 KB Output is correct
45 Correct 27 ms 2264 KB Output is correct
46 Correct 25 ms 2044 KB Output is correct
47 Correct 24 ms 2036 KB Output is correct
48 Correct 29 ms 2292 KB Output is correct
49 Correct 28 ms 2024 KB Output is correct
50 Correct 25 ms 2020 KB Output is correct
51 Correct 23 ms 1868 KB Output is correct
52 Correct 33 ms 2584 KB Output is correct
53 Correct 43 ms 2328 KB Output is correct
54 Correct 37 ms 2536 KB Output is correct
55 Correct 52 ms 2876 KB Output is correct
56 Correct 36 ms 2628 KB Output is correct
57 Correct 60 ms 3016 KB Output is correct
58 Correct 41 ms 2500 KB Output is correct
59 Correct 45 ms 2688 KB Output is correct
60 Correct 39 ms 2124 KB Output is correct
61 Correct 47 ms 2708 KB Output is correct
62 Correct 48 ms 2884 KB Output is correct
63 Correct 49 ms 2884 KB Output is correct
64 Correct 50 ms 2852 KB Output is correct
65 Correct 35 ms 2108 KB Output is correct
66 Correct 30 ms 2184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 844 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 788 KB Output is correct
5 Correct 2 ms 1152 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 4 ms 1300 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 3 ms 1228 KB Output is correct
14 Correct 3 ms 1228 KB Output is correct
15 Correct 2 ms 1304 KB Output is correct
16 Correct 3 ms 1304 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1304 KB Output is correct
21 Correct 5 ms 1456 KB Output is correct
22 Correct 5 ms 1644 KB Output is correct
23 Correct 4 ms 1484 KB Output is correct
24 Correct 7 ms 1612 KB Output is correct
25 Correct 8 ms 1612 KB Output is correct
26 Correct 8 ms 1612 KB Output is correct
27 Correct 7 ms 1668 KB Output is correct
28 Correct 8 ms 1612 KB Output is correct
29 Correct 7 ms 1612 KB Output is correct
30 Correct 7 ms 1660 KB Output is correct
31 Correct 8 ms 1612 KB Output is correct
32 Correct 7 ms 1612 KB Output is correct
33 Correct 7 ms 1676 KB Output is correct
34 Correct 7 ms 1676 KB Output is correct
35 Correct 9 ms 1612 KB Output is correct
36 Correct 8 ms 1644 KB Output is correct
37 Correct 16 ms 1996 KB Output is correct
38 Correct 20 ms 1992 KB Output is correct
39 Correct 26 ms 1996 KB Output is correct
40 Correct 28 ms 2212 KB Output is correct
41 Correct 27 ms 2124 KB Output is correct
42 Correct 23 ms 2036 KB Output is correct
43 Correct 26 ms 2368 KB Output is correct
44 Correct 35 ms 2368 KB Output is correct
45 Correct 27 ms 2264 KB Output is correct
46 Correct 25 ms 2044 KB Output is correct
47 Correct 24 ms 2036 KB Output is correct
48 Correct 29 ms 2292 KB Output is correct
49 Correct 28 ms 2024 KB Output is correct
50 Correct 25 ms 2020 KB Output is correct
51 Correct 23 ms 1868 KB Output is correct
52 Correct 33 ms 2584 KB Output is correct
53 Correct 43 ms 2328 KB Output is correct
54 Correct 37 ms 2536 KB Output is correct
55 Correct 52 ms 2876 KB Output is correct
56 Correct 36 ms 2628 KB Output is correct
57 Correct 60 ms 3016 KB Output is correct
58 Correct 41 ms 2500 KB Output is correct
59 Correct 45 ms 2688 KB Output is correct
60 Correct 39 ms 2124 KB Output is correct
61 Correct 47 ms 2708 KB Output is correct
62 Correct 48 ms 2884 KB Output is correct
63 Correct 49 ms 2884 KB Output is correct
64 Correct 50 ms 2852 KB Output is correct
65 Correct 35 ms 2108 KB Output is correct
66 Correct 30 ms 2184 KB Output is correct
67 Correct 52 ms 2756 KB Output is correct
68 Correct 3 ms 404 KB Output is correct
69 Correct 110 ms 3920 KB Output is correct
70 Correct 96 ms 3236 KB Output is correct
71 Correct 85 ms 3068 KB Output is correct
72 Correct 71 ms 2416 KB Output is correct
73 Correct 74 ms 2408 KB Output is correct
74 Correct 128 ms 3984 KB Output is correct
75 Correct 99 ms 3512 KB Output is correct
76 Correct 127 ms 4032 KB Output is correct
77 Correct 119 ms 4132 KB Output is correct